I asked a question like this last week. As the Page_load function ALWAYS gets fired before any events, like OnClick etc, i was looking for a way to trap events..
Ive discovered a way!! Im sure its probably well know but no-one replied to my post so here we go...
Say you have a btnSave <input> in your aspx file, all you need to do in the code behind page is to add and Attribute to that button at the very start of the Page_Load:
btnSave.Attributes.Add("onclick", "return btnSave_onClick();");
then, add a hidden <input> field into your page, say with an ID of hidSave, and give it a value=false.
then all you need to do is out a javascript function in your aspx page like this:
function btnSave_onClick()
{
Form1.hidSave.value="true";
return true;
}
this sets a run-time the value of the hidden field to true when the Save button is clicked.
Then, finally you can Request this value from the FORM like so:
blnSave = Convert.ToBoolean(Request.Form["hidSave"]);
and hey presto! now you have a boolean telling you whether someone has clicked a specific EVENT. And in your code behind you can just stick this in your Page_Load and not run the code in there if you so desire...
Hope that helps some, it certainly helped me!!
Axum
Ive discovered a way!! Im sure its probably well know but no-one replied to my post so here we go...
Say you have a btnSave <input> in your aspx file, all you need to do in the code behind page is to add and Attribute to that button at the very start of the Page_Load:
btnSave.Attributes.Add("onclick", "return btnSave_onClick();");
then, add a hidden <input> field into your page, say with an ID of hidSave, and give it a value=false.
then all you need to do is out a javascript function in your aspx page like this:
function btnSave_onClick()
{
Form1.hidSave.value="true";
return true;
}
this sets a run-time the value of the hidden field to true when the Save button is clicked.
Then, finally you can Request this value from the FORM like so:
blnSave = Convert.ToBoolean(Request.Form["hidSave"]);
and hey presto! now you have a boolean telling you whether someone has clicked a specific EVENT. And in your code behind you can just stick this in your Page_Load and not run the code in there if you so desire...
Hope that helps some, it certainly helped me!!
Axum