Flexible use of the _ dopostback Function

Source: Internet
Author: User
In. net, when all server controls are submitted to the server, the _ dopostback function is called. Therefore, flexible use of this function is of great help to us.
For example Program The simplest method is to use a string, such as string strbutton = <input type = "button" id = "button1">, output to the page, but it is difficult if we need this control to execute some server functions. here we can use the borrow _ dopostback function to complete the process. next, I will give an example to illustrate how to call it.

To run on the server side, we can declare an invisible linkbutton control. Generally, we want a control to be invisible and set the visible attribute to false. however, here we set the text attribute of the linkbutton to null to make the linkbutton invisible (why do we set it like this instead of directly setting the visible attribute? I will explain it below ), next, we can write some servers in the linkbutton. Code And then how to use the client control we dynamically generate to call the functions in the linkbutton. We can use a JavaScript function to implement Function Excuteonserver ()
{
// The first parameter is the ID of the control you want to submit to the server, and the second parameter is the event parameter.
_ Dopostback ('linkbuttonid ','');
}

Next, we only need to write onclick = "javascript: excuteonserver ();" in The onclick event of the dynamically generated button control ();", in this way, when we click this dynamically generated client control, it will execute the code in the linkbutton.

In this way, the dynamically generated client control is submitted to the server.
The last thing we want to talk about is why the linkbutton control is not visible through the visible attribute. when we set the visible attribute to false, the browser will not place this control on the page during parsing, that is, this control does not exist, therefore, when we call the _ dopostback function, we cannot find the control.

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.