Write Ajax todayProgramThe _ dopostback method is used to re-load data from the background. _ Dopostback is not a method written by myself. It is a method added to the page by Asp.net itself. After we run the Asp.net program, we will see the _ dopostback method in the generated HTML source code.CodeAs follows:
Code < Script Type = "Text/JavaScript" >
// <! [CDATA [
VaR Theform = Document. Forms [ ' Aspnetform ' ];
If ( ! Theform ){
Theform = Document. aspnetform;
}
Function _ Dopostback (eventtarget, eventargument ){
If ( ! Theform. onsubmit | (Theform. onsubmit () ! = False )){
Theform. _ eventtarget. Value = Eventtarget;
Theform. _ eventargument. Value = Eventargument;
Theform. Submit ();
}
}
// ]>
</ Script >
_ Dopostback description: _ Dopostback can implement the client control to call the server-side control response.
_ Dopostback method format: _ Dopostback (eventtarget, eventargument)
Parameters:Eventtarget: the client ID of the server control to be triggered.
Eventargument: Parameter
The two values can be obtained in the background using the following method:
Request ["_ eventtarget"]: gets the Control ID that raises the page PostBack.
Request ["_ eventargument"]: Get the parameter.
Example, Returns updatapanel, and obtains information through parameters.
1) Call dopostback to trigger the sending back:
_ Dopostback ('ctl00 _ contentplaceholder1_upmodulepower', 'jspostback ')
Note:
Ctl00_contentplaceholder1_upmodulepower: the client ID generated after the master page is added.
Jspostback: used to determine whether the callback is triggered by the JS control. Because updatepanel contains the sending back of other server controls, this parameter is used to distinguish between them.
2) obtain the parameters in the background pageload and obtain the data.
// Determine whether the callback is triggered by Js.
If (Request [ " _ Eventargument " ] = " Jspostback " )
{
// Call the related background method here
// ......
}
Other problems:
But when we call the _ dopostback function, sometimes a script error "the object does not exist" will occur when we call this function? This is because there is no _ dopostback function body in HTML. When you drag and drop controls with the auto-return function, set the autopostback attribute to true, when running, the system automatically adds the _ dopostback function body. Of course, the most direct method is to add a linkbutton. If linkbutton is added to the page, the page will load the JS required by PostBack in the page, and set its text attribute to null. Do not set the visible attribute, because if visible = false, when translated into HTML, the existence of linkbutton is ignored.