Here, we need to mention that asp.net programming provides the idea of server-side controls and client controls, but it still cannot be separated from the nature of HTML. The client and server must be submitted for interaction, there are two ways to submit get and post. get sends the connection address to the server, and the server obtains the information through the address parameters. Generally, these parameters are in plain text and can be seen in the browser address bar. While post is submitted to the server page through the input and other elements of the form, which is generally invisible. The server control of asp.net is actually a packaging of General HTML controls, which provide control parameters by hiding controls.
Here we will introduce a common function _ doPostBack, if it is ASP. net render generates this function automatically. For example, a page with the autopostback property and its property is true contains a datagrid page with the edit column.
_ DoPostBack sends control information to the server through the two hidden controls _ EVENTTARGET ,__ EVENTARGUMENT. __eventtarget is the name of the control to be called. If the control to be called is a child control, use '$' or ':' To separate the parent control: Child control, __eventargument, which is a parameter when an event is called.
The following shows how to call background events:
1. Create a project
2. Drag a server Button1, A DropDownList1, and a client Button
3. Set the AutoPostBack attribute of DropDownList1 to True, while that of Button1 to False.
4. Double-click Button1 and Write Response. Write ("hello:") in the event :");
5. Find the client Button in the HTML of the page and write onclick = "_ doPostBack ('button1 ','')"
6. Compile, run, and click the Button to see "Hello"
7. Check the source code and find the following lines are added
Copy codeThe Code is as follows:
<Script language = "javascript">
<! --
Function _ doPostBack (eventTarget, eventArgument ){
Var theform;
If (window. navigator. appName. toLowerCase (). indexOf ("netscape")>-1 ){
Theform = document. forms ["Form1"];
}
Else {
Theform = document. Form1;
}
Theform. _ EVENTTARGET. value = eventTarget. split ("$"). join (":");
Theform. _ EVENTARGUMENT. value = eventArgument;
Theform. submit ();
}
// -->
</Script>
And two hidden controls
Copy codeThe Code is as follows:
<Input type = "hidden" name = "_ EVENTTARGET" value = ""/>
<Input type = "hidden" name = "_ EVENTARGUMENT" value = ""/>
It is worth noting that the first parameter of _ doPostPack is case insensitive.
Careful people will find that in _ doPostBack, the submitted call is theform. submit (), which causes the onsubmit event validation of the Form to fail. Fortunately, this problem has been fixed in asp.net 2.0. Here we provide a solution for replacement. Insert the following code at the bottom of Form to ensure that the Code is valid on pages that are provided by render or not.
Copy codeThe Code is as follows:
<Script language = "javascript">
<! --
Function _ doPostBack_Ex (eventTarget, eventArgument)
{
Var theform;
If (window. navigator. appName. toLowerCase (). indexOf ("netscape")>-1 ){
Theform = document. forms [0];
}
Else {
Theform = document. forms [0];
}
If (! Theform. _ EVENTTARGET)
{
Theform. appendChild (document. createElement ("<input type = 'den den 'name = '_ EVENTTARGET'> "));
}
If (! Theform. _ EVENTARGUMENT)
{
Theform. appendChild (document. createElement ("<input type = 'den den 'name = '_ EVENTARGUMENT'> "));
}
Theform. _ EVENTTARGET. value = eventTarget. split ("$"). join (":");
Theform. _ EVENTARGUMENT. value = eventArgument;
If (typeof (theform. onsubmit) = "function "))
{
If (theform. onsubmit ()! = False)
{
Theform. submit ();
}
}
Else
{
Theform. submit ();
}
Function _ doPostBack (eventTarget, eventArgument)
{
_ DoPostBack_Ex (eventTarget, eventArgument );
}
}
// -->
</Script>