The script generated by the Asp.net server conflicts with the script manually added.

Source: Internet
Author: User

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 ').

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.