_ Dopostback usage

Source: Internet
Author: User

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.

 

 

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.