raise server event from the client

Last post 05-16-2008 5:32 PM by vikas_mahajan. 3 replies.

Sort Posts:

  • raise server event from the client

    06-05-2007, 6:17 AM
    • Loading...
    • yanivhanya
    • Joined on 12-16-2002, 11:41 PM
    • israel
    • Posts 284

    i have control that i use to raise mostlly javascript events, but in one condition i need to go to the server, how can i raise server event using javascript?

  • Re: raise server event from the client

    06-05-2007, 8:23 AM
  • Raise server event from the client with javascript

    06-05-2007, 9:42 AM
    Answer
    • Loading...
    • JoshStodola
    • Joined on 01-16-2007, 2:17 PM
    • Heartland of America
    • Posts 3,162

    The way I have always accomplished this....

    Put a hidden button on the form:

        <asp:Button ID="btnHidden" runat="server" style="display:none;" />
    And the server-side code you want to execute goes in the code-behind for this button:
        Protected Sub btnHidden_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHidden.Click
            'Code goes here
        End Sub
    Now, you can programmatically invoke the click of this button with javascript, which will fire the code-behind:  
        document.getElementById('btnHidden').click();
      

    Hope this helps!  Don't forget to mark the most helpful post(s) as Answer for the sake of future readers.

    Josh Stodola ← Come check out my blog!
  • Re: Raise server event from the client with javascript

    05-16-2008, 5:32 PM

     Hello,

    document.getElementById('btnHidden').click();
    the above javascript code doesn't work in firefox though it works fine in IE.
    Is there any workaround to make it work in firefox browser.
     
    Thanks in advance 
    ~VM 
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter