Add client js events to controls in C #

Source: Internet
Author: User

Make an input interface today. There is a need to select a different one based on a DropDownList. Different Input interfaces are displayed in the following sections. If you place the RESPONSE event on the server, you must frequently click the page. You just want to put it in the customer to display and hide the corresponding input interface.

It can also be implemented on the server side Using ajax without refreshing the page. But I think there are more direct and simpler methods that can be implemented with a js event.
 

However, the DropDownList does not include Button and other controls provide some front-end events such as "OnClientClick", only server events.
 

Think of it, all the C # Page code will eventually generate HTML, and js events will eventually be carried in the browser, based on Html. If the HTML control generated by the server control has any js events, we should be able to add corresponding events to it in aspx.

The Htm generated by DropDownList is an element <Select> with an onchange event, so we can also add an onchange () event to DropDownList. We usually use this method, in the Page_Load event of the background file, add an onchange () event to the DropDownList with the id of ddlExamType:
 

DdlExamType. Attributes. Add ("onchange", "SelecteChanged (" + this. ddlExamType. ClientID ")");

Front-end js function: SelecteChanged ()
 

<Script language = "javascript">
Function selectChange (objID ){
Var ddlExamType = document. getElementById (objID );
If (bool ){
......
}
Else {
......
}
}
</Script>
 

Summary: The C # server-side control adds Attributes. Add () to the control by generating js events of the corresponding control When html is generated.
 

Related Article

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.