How to call server side button event from javascript function

Hello Friends,

Today I am going to describe how to call server side event from client side.

we can do this by different ways like web service and Page Methods, using jquery, using scriptmanger and __dopostback, using javascript etc.

Today I will show you how to call a server-side ASP.NET button event from client-side using JavaScript function.

See the below aspx code;


   
This is test page :

You can see that, I have defined one server side button with onclick event.

Here, I have also defined aspx label and client side button.

I have used client side button event for calling the server side button event; where I have write test message in aspx label.

see below code for aspx code behind button event


protected void btnTest_Click(object sender, EventArgs e)
{
    lblMessage.Text = "Test message";
}

Now how can we call this event from client side function; see the below client side funtion


function TestCall()
{
     var btnTest = document.getElementById("<%= btnTest.ClientID %>");
     btnTest.click();
}

That’s it.

Hope this will help you !!….

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>