Modather Sadik
Answered On : Oct 5th, 2012
The secret is in the
Tag and the hidden field "id="__EVENTVALIDATION", as you know that the form element supports the Event Attributes "means the abillity to fire scripts when an action happened like button click", The hidden field value maintains all possible postbacks of your controls throw javascript.
Code
<body>
<form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTU4NzY5NTcwN2Rk" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLyjNtAApm8wPAMAoLquO0O" />
</div>
<div>
<input type="submit" name="btnRedirect" value="Redirect" id="btnRedirect" />
<input type="submit" name="btnEvent" value="text" id="btnEvent" />
<br />
<br />
<span id="lbl">Label</span>
</div>
</form>
</body>
Login to rate this answer.
rupinder
Answered On : Apr 17th, 2013
, control renders by default an input of type="submit", which submits the form, using the browsers default mechanism.
ASP .Net identifies which button was clicked, by checking the posted values.
When a browser submits a form it writes in the POST request the name and value of the clicked button among with the names and values of the other inputs, excluding the other submit inputs.
So the name of one single submit input is sent to the server and in this way ASP .Net checks which button was clicked.
ASP .Net generates some javascript which will do the job
var theForm = document.forms[form1];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
Notice _EVENTTARGET and _EVENTARGUMENT fields. These fields are set so ASP .Net will know which button was clicked on client.
The value of EVENTTARGET will be read by ASP .Net and based on this will fire Click event of the control
Code
<asp:Button />, control renders by default an input of type="submit", which submits the form, using the browsers default mechanism.
ASP .Net identifies which button was clicked, by checking the posted values.
When a browser submits a form it writes in the POST request the name and value of the clicked button among with the names and values of the other inputs, excluding the other submit inputs.
So the name of one single submit input is sent to the server and in this way ASP .Net checks which button was clicked.
ASP .Net generates some javascript which will do the job
var theForm = document.forms[form1];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
Notice _EVENTTARGET and _EVENTARGUMENT fields. These fields are set so ASP .Net will know which button was clicked on client.
The value of EVENTTARGET will be read by ASP .Net and based on this will fire Click event of the <asp:Button /> control
Login to rate this answer.