Click here to Skip to main content
11,789,512 members (41,690 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript jQuery , +
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
Edited 23-Apr-13 23:17pm
Somnath Leo at 24-Apr-13 7:59am
$('[id$=btnYes]').click(); Am not getting the $ sign in the selector?
Brian A Stephens at 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 at 25-Apr-13 2:48am
Thank u i got it now...
Somnath Leo at 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 at 24-Apr-13 5:19am
thanks but it doesn't work for me
mvamsianil at 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 at 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>

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

  Print Answers RSS
0 OriginalGriff 954
1 Maciej Los 765
2 KrunalRohit 666
3 CPallini 606
4 Richard MacCutchan 420

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2015
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