Server events of server controls generally correspond to events of client controls. For example, the selectedindexchanged event of dropdownlist corresponds to the onchange event of HTML <SELECT>. If you want to manually add an onchange event, two onchanges will be generated on the client, and the browser will ignore one. For example, the user wants to save the dropdownlist option to the database whenever it is changed (although not very common, but it does), but also wants to remind the user whether to save it. Obviously,CodeIt should be placed in the selectedindexchanged event, and the reminding work should manually add an onchange event. The result is that only one onchange can be executed. The correct method should be to add an invisible Save button, which is generated by calling this button in the manually added onchange eventProgram.
The page_load method is as follows:
Dim scmd as string
Scmd = page.Clientscript.Getpostbackclienthyperlink (btnupdate ,"")
If not page. ispostback then
Dropdownlist1.attributes. Add ("onchange", "confirmupdate (" "& scmd &""")")
End if
The confirmupdate function is as follows:
<Script language = "JavaScript">
Function confirmupdate (CMD ){
If confirm ("are you sure to update ?")
Eval (CMD );
}
</SCRIPT>
Note: The clientscriptmanager. getpostbackeventreference method andClientscriptmanager.GetpostbackclienthyperlinkThe functions of the methods are the same. scripts are generated on the client. When a specific event of the control is triggered, it can be sent back to the server.
They behave differently on the client,GetpostbackclienthyperlinkPerformance:Javascript :__ dopostback ('mycontrol1', 'myanchor1 '), Getpostbackeventreference: __dopostback ('mycontrol1', 'myanchor1 ').