Onclientclick and onclick are both used!

Source: Internet
Author: User

In fact, sometimes dual verification is required between the client and the server. Why? Biguo said that in the text box of a user name, we can only enter letters and numbers through JS verification on the client, and there cannot be special characters! Normally, there is no problem, but there is always a shame to find ways to "Destroy". At this time, we need to perform a dual verification! To put it bluntly, it means that both the server and the client are verified!

For example, a button has The onclick event and onclientclick attributes. The former is generally a server-side click event! The latter is the client click event!

Let's do a test! Add the following code on the default. aspx page!

 

<Script language = "JavaScript" type = "text/JavaScript">
Function buttonclick (){
Alert ("I Am a client Click Event ");
Return false;
}

</SCRIPT>

Page code:

<Form ID = "form1" runat = "server">
<Div>
<Asp: button id = "button1" runat = "server" text = "some buttons are server-side controls. The onclientclick event is used by default. Please disable the JS function of the browser to experience it"
Onclick = "button#click" onclientclick = "Return buttonclick ();"/>
<Asp: Label id = "label1" runat = "server" text = ""> </ASP: Label>
</Div>

</Form>

CS file code:

Protected void button#click (Object sender, eventargs E)
{
This. label1.text = "I Am a server Click Event ";

}


Let's see what the effect is? You may find that only the code in JS is popped up! That's right. This is exactly what we want. Use return false to "Block" server verification! What are the benefits? You don't need to refresh the page!

You disabled the Script Function of the browser. Try again to see what the effect is?

By re-checking, the user's illegal input can be ensured. This is what we want!

 

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.