asp.net (C #) methods for adding client JS events to controls _ practical tips

Source: Internet
Author: User
On the server side, you can also use Ajax to implement, do not brush the page. But I think there is a more direct and simple way to use a JS event is achievable.
However, the DropDownList button and other controls provide some things like "onclientclick" foreground events, only server-side events.
Think of all the C # page code that ultimately generates HTML,JS events that are ultimately shipped in the browser, based on HTML. The HTML control that the server-side control eventually generates has a JS event, and we should be able to add the corresponding event to it in ASPX.
DropDownList generated htm is the element <Select> is onchange event, so we can also give DropDownList add onchange () event, we usually use the method, in the background file Page_Load event, add the onchange () event to the DropDownList with ID Ddlexamtype:
DDLEXAMTYPE.ATTRIBUTES.ADD ("onchange", "selectechanged" (' +this.ddlexamtype.clientid ")");
The JS function defined by the foreground: selectechanged ()
Copy Code code as follows:

<script language= "JavaScript" >
function Selectchange (ObjID) {
var ddlexamtype = document.getElementById (ObjID);
if (bool) {
......
}
else {
......
}
}
</script>

Summary: C # server-side control, when generating HTML corresponding control what JS event, we can add to the control Attributes.Add ().

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.