C # common JS Code (Memo)

Source: Internet
Author: User
1. Button front and back-end events
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"
Onclientclick = "alert ('room-side verification, blocking server-side submissions '); Return false;"/>

2. Register related events: onblur, onclick, onchange
This. textbox1.attributes. Add ("onchange ",
"Alert ('data changed, check whether the input meets the rule ');");

3. Registration attributes:
This. textbox1.attributes. Add ("readonly", "true ");

4. Introduce JS files
Front-end HTML page:
<SCRIPT type = "text/JavaScript" src = "jscript. js" Language = "JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function fn_name ()
{
Alert ("JS ");
}
</SCRIPT>
Backend CS page:
This. registerclientscriptblock ("jsfile ",
"<SCRIPT type = 'text/JavaScript 'src = 'jscript. js' Language = 'javascript '> </SCRIPT> ");

5. When you click the button, the related column is not empty.
Function checkempty (txtobj, msgshow)
{
If (txtobj. value = "")
{
Alert (msgshow );
Return false;
}
}

<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"
Onclientclick = "Return checkempty (textbox1, 'textbox1 cannot be blank ')"/>

6.
// Select whether to use chcekbox
// Control whether the textbox is input.
Function chktextbox (chkobj, txtobj)
{
If (chkobj. Checked = true)
{
Txtobj. value = "";
Txtobj. readonly = false;
Txtobj. Focus ();
}

If (chkobj. Checked = false)
{
Txtobj. value = "";
Txtobj. readonly = true;
}
}

<Input id = "checkbox1" type = "checkbox" onclick = "chktextbox (checkbox1, textbox1)"/>
... To be continued

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.