Reputation:
i have a javascript function in aspx file
now i use vb as back in asp.net
now i use postback from javascript like this
<script type="text/javascript">
function s()
{
return this.Page.GetPostBackEventReference(this,**"1"**);
}
</script>
now in my vb code
i want to check like this
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindList()
If (IsPostBack)
Then
Dim eventArg As String = Request(**"_EVENTARGUMENT**")
MsgBox(eventArg)
If (eventArg <> "") Then
Label5.Text = "hiiiiiii"
End If
End If
End Sub
now i dont get that "1" in my vb code
i want to get it because i want check when i get page_load event by post back by this javascript
what to do?
Upvotes: 0
Views: 1988
Reputation: 17370
This is how I do it: Javascript:
<script>
__doPostBack("eventTargetHere", eventArgumentsHere);
</script>
Server Side:
If Request("__EVENTTARGET") IsNot Nothing And Request("__EVENTTARGET").ToString() = "eventTargetHere" Then
Dim MyArgs As String = Request("__EVENTARGUMENT").ToString()
End If
Good luck!!
Upvotes: 1
Reputation: 8787
There may be another cleaner way, but the way that I pass values to the codebehind is using hidden input server controls. Then you can have the javascript change the value of the hidden control, and reference that value from the code behind. This method also allows an indefinite number of arguments of different types to be passed to the codebehind during the postback, simply by adding and modifying more hidden server controls.
<asp:HiddenField ID="hidden1" runat="server">
function s(){
$('<%=hidden1.ClientID%>').val(EVENT_ARG);
//Fire postback;
}
and the codebehind will just reference the hidden1.Value.
Upvotes: 1