When using a LinkButton
the doPostBack()
function is rendered in the page and when the button is clicked doPostBack()
is invoked at client side submitting the form to the server and also sending information in two hidden fields called EVENTTARGET
and EVENTARGUMENT
. The EVENTTARGET
holds the control name which caused the postback and EVENTARGUMENT
holds any info.
With this ASP.NET engine gets the control name from EVENTTARGET
argument which caused postback and calls RaisePostBackEvent()
event to call right server side event handler. I understand how doPostBack()
works and how server side event handler is called.
However for a normal server button how is the correct button click at server side called? How is ASP.NET notified on the control name that was clicked client side?
A normal ASP.NET Button
is rendered as a HTML <input type="submit">
element with a unique name
attribute. By default this HTML element will trigger an HTTP POST to the HTML form associated with the current ASPX page.
When an HTTP POST happens a sequence of control-name/current-value pairs, known as form data set, is constructed from the successful controls inside the form, for example the textual value inside a text box is transmitted like this. A pair with the name of the button that triggered the submit is also sent to the server and that's how ASP.NET know which button triggered the HTTP POST.
The HTML specification guarantees that only the successful controls inside the form are considered for the form data set that is posted and since the definition of a successful control contains the following rule:
If a form contains more than one submit button, only the activated submit button is successful.
then ASP.NET can check the posted form data set to check if any normal button was triggered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With