Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  102] [ 3]  / answers: 1 / hits: 24028  / 13 Years ago, wed, june 15, 2011, 12:00:00

I'm calling a partial postback from javascript like so:



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


It does 1/2 of what I need it to. It does call a partial postback, just for my UpdatePanel.



Now the tricky part. I'm trying (somehow) to reference the second argument of __dopostback in my code behind. 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 might be completely wrong (as with everything else I try to do with ASP). I'm suspecting that my codebehind is grabbing the event argument from the page instead of the panel, but I really don't know, Any ideas?


More From » asp.net

 Answers
16

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



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


I recommend you to 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 it would be shorter:



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


If it doesn't work I would like to suggest you to put one hidden field inside 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 like above:



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


In first scenario you are able to get __EVENTARGUMENT in server side:



String args = Request[__EVENTARGUMENT];


If first scenario doesn't work you can use something like that:



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

[#91692] Tuesday, June 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 4 Years ago
;