How to call/fire server side button click event from/using JavaScript

{0 Comments}

In this article to demonstrate how you can fire or call a server side button event from or using JavaScript. I used an html button to access the server side button event.

Here we have to create a JavaScript function which will find the button (asp button id) and fire a click event of the asp button control. And finally fire that JavaScript function using html button, in place of html button you can use any thing like a timer to fire JavaScript event. Following is the snippets which you can use or modify according to yourself.

javascript code:

 Javascript |  copy code |? 
1
<script type="text/javascript">
2
    function call_server_btn_event()
3
    {
4
    document.getElementById("server_btn").click();
5
    }
6
    </script>

aspx or designer code:

 HTML |  copy code |? 
1
     <asp:Button ID="server_btn" runat="server" Text="server_btn" OnClick="server_btn_Click"
2
            Style="display: none;" />
3
        <input id="Submit1" type="submit" value="html_btn" onclick="call_server_btn_event()" />
4
   

c# code behind code:

 C# |  copy code |? 
1
protected void server_btn_Click(object sender, EventArgs e)
2
    {
3
        Response.Write("write or do any thing");
4
    }

Leave a Comment

Your email address will not be published.