asp.net|server| Interaction | control
Before writing an ASP's program, you know that only type is set to submit button to trigger the form submission data to the server side.
For example: The button in asp.net is equal to <input type= "submit".
But now many of the ASP.net control can be arbitrary and server-side interaction, such as: LinkButton.
How does this happen?
Is it a new way of doing it?
In fact, this is only a flexible way of Microsoft.
Let's take a look at the client's code first.
I am here a page with LinkButton,
In fact LinkButton in the client is equal to the HTML of a.
Let's see why LinkButton can also interact with the server side?
When we click the right button to view the source code of the page, see:
<script type= "Text/javascript"
<!--
var theform = document.forms[' ctl00 '];
if (!theform) {
theform = document.ctl00;
}
Function __doPostBack (eventtarget, eventargument) {
if (!theform.onsubmit | | (Theform.onsubmit ()!= false)) {
theform.__eventtarget.value = eventtarget;
theform.__eventargument.value = eventargument;
theform.submit ();
}
}
//;
</script>
<a id= "SimpleLinkButton1" href= "Javascript:__dopostback" (' SimpleLinkButton1 ', '] ">click me</a>
<input type=" hidden "name=" __eventtarget "id=" __eventtarget " Value= "" "/>
<input type=" hidden "name=" __eventargument "id=" __eventargument "value=" "/>
As you can see from the code above, SimpleLinkButton1 is a link that submits the form by client code.
And two of these hidden fields, which are used to exchange data, are to assign the __doPostBack two parameter values to the two hidden fields.
This is why LinkButton also has the most intuitive reason for submitting data.
So how does this code build?
We see LinkButton's source code to know clearly:
protected internal override void OnPreRender (EventArgs e)
{
Base. OnPreRender (e);
if (this. Page!= null) && this. Enabled)
{
This. Page.registerpostbackscript ();
if (this. CausesValidation && (this. Page.getvalidators (this. ValidationGroup). Count > 0)) | | !string. IsNullOrEmpty (this. PostBackUrl))
{
This. Page.registerwebformsscript ();
}
}
}
The above is just to put yourself in the process of learning some experience recorded so as to prevent yourself from forgetting.
Also hope and everyone a lot of exchanges!