Click here to Skip to main content
Rate this: bad
good
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?')) {
                $('[id$=btnYes]').click();
            }
        } else {
            $('[id$=btnYes]').click();
        }
        return false;
    }
Posted 23-Apr-13 23:52pm
Edited 24-Apr-13 0:17am
v2
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

Hi Yvonne192,
 
OnClientClick="return(cfrm());"
 
should be
 
OnClientClick="return cfrm();"
 
in the Button tags.
 
Please modify and click the solved button if this helped you.
 
Thank you,
Vamsi
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

Hi,why not your code use jQuery completely ?
try this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("#btnCalculate").click(function(){
			var consultFee = $('[id$=txtConsultFee]').val();
			//consultFee=600;
			if(consultFee>500){
				if(confirm('Confirm?')){
					alert(123);
					// do something;
				}else{
					alert(456);
					//do something;
				}
			}
			return false;
		});
	})
</script>
<asp:button id="btnCalculate" runat="server" text="Calculate Claim" xmlns:asp="#unknown" />
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
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