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.