I have this code behind :
protected void btn_Click(object sender, EventArgs e)
{
if (btn != null && btn.Checked)
{
Response.Redirect(string.Format("get.aspx?a={0}&b={1}",
a.SelectedValue, b.SelectedValue));
}
}
And I have a Checkbox :
I am tryong to call that function btn_Click in jquery :
$(document).ready(function () {
if ($('#btn').is(':checked')) {
$(button).trigger("btn_Click");
}
});
But not worked!!!
Why? Thanks.
Brijendra GautamPosted Mar 26, 2014, 10:13 AM
If you check the html source of page in browser then you will be able to find the this function is called somewhere.
So, what I was suggesting is we can also call that event in our own JavaScript code by calling
__doPostBack('
And the advantage of calling like is we'll not lose the page context. If we call the server side code using Ajax and WebMethods then it is same like calling WebService code that is independent of page context. We can't access control's on page in that code.
Chevy Mark SunderlandPosted Mar 26, 2014, 4:39 AM
Jignesh TrivediPosted Mar 26, 2014, 1:36 AM
hi,
As per my knowledge trigger is fired client side event not server side event.
to call server side code please refer
http://weblogs.asp.net/karan/archive/2010/09/12/calling-server-side-method-using-jquery-ajax.aspx
hope this will help you.
Brijendra GautamPosted Mar 25, 2014, 10:58 AM
__doPostBack('btn','');