The following content is taken from"
Qiben Sakura, snow blowing on paper ":
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 exampleProgramThe 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. 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. In general, 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. Then, we can use a JavaScript function to call the functions in the linkbutton through the dynamically generated client control.
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 need 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.