Small details of OnClick in work experience; onclick in work experience

Source: Internet
Author: User

Small details of OnClick in work experience; onclick in work experience

Today I encountered a problem about OnClientClick and OnClick,Let's take a look at the differences in the following code:

<Asp: Button ID = "btnQuery" runat = "server" Text = "query (Q)" AccessKey = "Q" OnClientClick = "btnQuery (); "OnClick =" btnQuery_Click "CssClass =" nButton "/>
<Asp: Button ID = "btnQuery" runat = "server" Text = "query (Q)" AccessKey = "Q" OnClientClick = "return btnQuery (); "OnClick =" btnQuery_Click "CssClass =" nButton "/>
One return is added to the OnClientClick method.

OnClientClick = "btnQuery ();" This will certainly execute the btnQuery method. However, no matter whether the return value is true or false, it will jump to the OnClick event. That is to say, when our judgment is incorrect, will also go to the cs class to execute the background code, equivalentThe OnClientClick event does not play its role. 

If the OnClientClick event is defined, The OnClick event will be executed only when the return true event is returned. It was actually the reason for the return of a word, and it took me an entire hour.

During verification and judgment, some verifications can be determined on the page, without the need to go to the cs class in the background, let's just talk about the js judgment that contains special characters in the text box.

In fact, it is very easy to write in cs. The Code is as follows:

this.TextBox1.Text.Trim().Contains("$")
But we need to put it in front-end js, but it won't work. Let's take a look at the following code:

txtNum.value.trim().indexOf('$')>= 0
Well, this is a little bit of knowledge sharing, little knowledge, great wisdom!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.