Steven Zack
Steven Zack

Reputation: 5104

how to set OnClientClick to be true?

I wonder how to use jquery click a button and set it's OnClientClick to be true, so the validation process will not run. I use

$("[id$='btn_Save']").attr('OnClientClick', true);
     $("[id$='btn_Save']").Click();

But it does not work.

Upvotes: 0

Views: 1738

Answers (3)

Matt
Matt

Reputation: 1911

try this:

ValidatorsEnabled(false); // This disables all .NET client-side validation
$("[id$='btn_Save']").Click();

Upvotes: 0

gbs
gbs

Reputation: 7276

1: attr('OnClientClick', true) is totally wrong.

2: OnClientClick won't help you stopping to fire validation.

Set CausesValidation="false" for your button so it don't fire Validation.

Edit: What I meant is:

 <asp:Button ID="Button1" runat="server" Text="Save" CausesValidation="false" />

Upvotes: 1

balexandre
balexandre

Reputation: 75103

you mention OnClientClick so I'm assuming ASp.NET (you should put this as a tag).

But why will you want such thing?

<asp:button 
    id="btn_Save" 
    runat="server" 
    onclientclick="doSomething()" 
    text="Save" />

the method doSomething will be called and if that method return true, it will continue and do the PostBack.

if you want to do something before or after just add the function to the property, for example:

onclientclick="doThis(); doSomething();"

or

onclientclick="doSomething(); doThis();"

Upvotes: 0

Related Questions