Click here to Skip to main content
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 23:52pm
Edited 24-Apr-13 0:17am
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>
<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
0 OriginalGriff 345
1 DamithSL 140
2 Zoltán Zörgő 120
3 Afzaal Ahmad Zeeshan 105
4 Sergey Alexandrovich Kryukov 99
0 enhzflep 40
1 Richard Deeming 25
2 OriginalGriff 10
3 Anddos 10
4 Kornfeld Eliyahu Peter 10

Advertise | Privacy | Mobile
Web02 | 2.8.150224.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