how to pass a variable to a button click event?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    how to pass a variable to a button click event?

    can any one tell me if there is a way to pass a string variable to a button click event? ultimately I am looking to fire client side Javascript "__doPostBack(' Button1','click ','')" and have the server-side button event retrieve the string I have set.

    for example: in Javascript -
    I have set this string variable --> '123456'
    I call a do postback of the button click -->"__doPostBack( 'Button1','clic k','')"

    then: in vb.net -
    the button1_click event fires
    what is the method for retrieving that variable '123456' from the Javascript code?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I know little about Javascript.
    Can you do custom events with eventargs that you define yourself?
    If so then when the button is clicked, raise a custom event that takes a TextArgs object that you defined.

    Comment

    • yarbrough40
      Contributor
      • Jun 2009
      • 320

      #3
      I hesitated to put this question into the Javascript forum to begin with.. .

      It seems logical to be able to create a custom event to call from the client. Not sure how that all would work exactly. Seems to me there has to be a simple way to fire client-side code which sends a variable to the server and I guess that's all I'm really looking for.

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        here's the solution I came up with. I passed my variable in the Eventarguement of the button - just thought I'd share....

        (setup1) in the Page Load() event set the Button1.OnClien tClick event to fire the below js code:
        ----javascript---
        Code:
         
        var myform = document.form1;  
        myform.__EVENTTARGET.value = "";  
        myform.__EVENTARGUMENT.value = "first,second,third,forth";  
        myform.submit();
        (setup2) in the Button1 click event input the beloe code:
        ---vb.net---
        Code:
         
        Button1_click()event
        
        Dim s As String = Request.Params("__EVENTARGUMENT").ToString
                    Response.Write(word & "<br>")

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          You could also use a HiddenField.
          I use HiddenFields to pass information generated/modified by JavaScript that the server code requires to do calculations.

          You should post ASP.NET related questions in the ASP.NET forum ;)
          I've moved you're thread there.

          -Frinny

          Comment

          Working...