Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 23-Apr-13 23:17pm
v2
Comments
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

Hi Yvonne192,

JavaScript
OnClientClick="return(cfrm());"


should be

JavaScript
OnClientClick="return cfrm();"


in the Button tags.

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

Thank you,
Vamsi
 
Share this answer
 
Comments
Yvonne192 24-Apr-13 5:19am    
thanks but it doesn't work for me
RelicV 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?
Hi,why not your code use jQuery completely ?
try this
JavaScript
<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" />
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900