0

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?

Joel Coehoorn
418k114 gold badges581 silver badges818 bronze badges
asked Feb 6, 2012 at 18:42
1
  • You meant "now what to do"... :) Commented Feb 6, 2012 at 18:44

2 Answers 2

1

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.

answered Feb 6, 2012 at 18:47
Sign up to request clarification or add additional context in comments.

Comments

1

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!!

answered Feb 6, 2012 at 18:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.