ASP.NET UpdatePanel and Javascript __dopostback

I am invoking a partial postback from javascript as follows:

function GetPolicyClick() {"__dopostback('UpdatePanel1', 'PostCall')";} 

He does 1/2 what I need. It causes a partial postback, only for my UpdatePanel.

Now the tricky part. I am trying (somehow) to refer to the second __dopostback argument in my code. This does not work:

 Private Sub UpdatePanel1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdatePanel1.Load Dim MyArg As String = Request("__EVENTARGUMENT") End Sub 

I just get an empty string.

Of course, what I'm trying to do may be completely wrong (as with everything else I'm trying to do with ASP). I suspect my codeword captures an event argument from a page instead of a panel, but I really don't know, Any ideas?

+6
source share
1 answer

If you want to put some value inside _EVENTARGUMENT , you must do it with javascript before submitting the form with _doPostBack ('UpdatePanel1', '') , because __EVENTTARGET is a hidden field and in your html document it looks like this:

 <input type="hidden" value="" id="__EVENTARGUMENT" name="__EVENTARGUMENT"> 

I recommend you do something like this:

 function setArgAndPostBack() { var arg = document.getElementById('__EVENTARGUMENT'); var arg = document.getElementById("__EVENTARGUMENT"); arg.value = 'something you want to put to server'; __doPostBack('UpdatePanel1', ''); } 

If you use jQuery this will be shorter:

 function setArgAndPostBack() { $("#__EVENTARGUMENT").val('something you want to put to server'); __doPostBack('UpdatePanel1', ''); } 

If this does not work, I would suggest you put one hidden field inside the Update panel:

 <asp:UpdatePanel runat="server" ID="UpdatePanel1"> <ContentTemplate> <asp:HiddenField ID="hdnData" value="" runat="server" /> <!-- your content goes here --> </ContentTemplate> </asp:UpdatePanel> 

And then do the same work as above:

 function setArgAndPostBack() { //Here hidden field is filled with your data $("#<%=hdnData.ClientID%>").val('something you want to put to server'); __doPostBack('UpdatePanel1', ''); } 

In the first scenario, you can get __EVENTARGUMENT from the server side:

 String args = Request["__EVENTARGUMENT"]; 

If the first script does not work, you can use something like this:

 String args = hdnData.Value;//This works even in Page_Load function. 
+11
source

Source: https://habr.com/ru/post/890624/


All Articles