How ASP.net controls interact with the server

Source: Internet
Author: User
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!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.