views:

16

answers:

2

I am having a problem with my code

if (text.length < 1)

       {
           args.IsValid = false;
           $('#<% = cmdSaveRequest.ClientID()> %>').removeAttr('click'());

       }
       else 
       {

           $('#<% = cmdSaveRequest.ClientID()> %>').click(savingData());
           args.IsValid = true;
       } 

when I assign click event like

$('#<% = cmdSaveRequest.ClientID() %>').click(savingData());

it executes the saving data function Is there any way to bind the click event to button but whiteout executing the function just bind it and after user clicks the button then the function executes?

+1  A: 

Try

$('#<% = cmdSaveRequest.ClientID() %>').click(savingData);

No paranthesis by savingData

RaYell
Thank you very much this worked like charm
Adem
A: 

You either must pass the function reference with

$('#<% = cmdSaveRequest.ClientID()> %>').click(savingData);

or you call/apply the function within an anonymous function

$('#<% = cmdSaveRequest.ClientID()> %>').click(function(e){
   savindData.apply(this, arguments);
});
jAndy