Click here to Skip to main content
13,152,454 members (37,178 online)
Rate this:
Please Sign up or sign in to vote.
I need to use show the confirm message. I am calling the method from 'btnCalculate' clientclick event. It calls the method if it's the first time. but if i click the button the second time, the method is not found. below is my code. Please advice. Thank you so much..
<asp:Button ID="btnYes" runat="server" OnClick="btnYes_Clicked" />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate Claim" OnClientClick="return(cfrm());"/>
function cfrm() {
        var  consultFee = '0';
        consultFee = $('[id$=txtConsultFee]').val();
        if (consultFee > 500) {
            if (confirm('Confirm?')) {
        } else {
        return false;
Posted 23-Apr-13 22:52pm
Updated 23-Apr-13 23:17pm
Somnath Leo 24-Apr-13 7:59am
$('[id$=btnYes]').click(); Am not getting the $ sign in the selector?
Brian A Stephens 24-Apr-13 8:23am
The $ in the selector indicates that the id attribute should END with the given value, rather than being equal. It's one approach when using ASP.NET web forms, which generate their own IDs on the fly.
Somnath Leo 25-Apr-13 2:48am
Thank u i got it now...
Somnath Leo 25-Apr-13 2:56am
Add preventDefault() in your code
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Yvonne192,


should be

OnClientClick="return cfrm();"

in the Button tags.

Please modify and click the solved button if this helped you.

Thank you,
Yvonne192 24-Apr-13 5:19am
thanks but it doesn't work for me
mvamsianil 24-Apr-13 5:25am
Are you using jquery and if so and if you kept this in ready method

$(document).ready() or jQuery(document).ready()

then anything within the ready() function will only be called once - when the page is loaded. It waits until the entire DOM is loaded before executing that code.

Try to keep that function outside of that and let me know about it.
Brian A Stephens 24-Apr-13 8:31am
[In reply to mvamsianil] Yes, she is using jQuery (notice the jQuery selectors in the code). jQuery code should generally be inside a document.ready callback (I'm not sure whether this is), but I don't understand your comment. The code that DEFINES the function will be run only once whether it's in a document.ready or not - it's just the timing of the definition that would change. The click event should call the function every time.

Have you debugged in the browser to step through and see what's happening?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi,why not your code use jQuery completely ?
try this
<script src=""></script>
<script type="text/javascript">
			var consultFee = $('[id$=txtConsultFee]').val();
					// do something;
					//do something;
			return false;
<asp:button id="btnCalculate" runat="server" text="Calculate Claim" xmlns:asp="#unknown" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100