Validation worked fine until I added a OnClientClick javascript to prompt the use to make sure they want to save the form data back to a sql database. Is my syntax worng or does the OnClientClick over ride the validation?
See below for my asp button control syntax
<asp:Button
ID="btSaveForm"
runat="server"
Style="z-index: 138; left: 764px; position: absolute; top: 726px"
Text="Save Form Data"
Width="151px"
CausesValidation="True"
OnClientClick="javascript: return confirm('Are you sure you want to add this estimate data?')"
/>
That's almost correct. Make sure that statement returns false.
if (! confirm('Are you sure you want to add this estimate data??')) return false;
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
Sorry to dredge this up from the dead, but i am unable to get this working with validation on my aspx pages. The following:
btnSaveCardHolder.Attributes.Add("OnClick",
"if (! confirm('Are you sure you want to save the changes made to this card holder?')) return false;");
Gives me the confirmation dialog, but breaks validation. This:
btnSaveCardHolder.Attributes.Add("OnClientClick",
"if (! confirm('Are you sure you want to save the changes made to this card holder?')) return false;");
Doesn't give me the dialog, and validation is fine. Is there a fix for this problem out there?
OnClientclick is a server side attribute and as such adding it to a control in this mechanism is doing nothing other than invalidating the HTML control - non standard attribute in HTML.
For your requirements the following is applicable
In ASP.net 1.1 to execute client side script on the client click event you would use (note the casing) -
Me.SubmitButton.Attributes.Add("onclick", "javascript:return confirm('You wish to do this?")
In ASP.net 2.0 you would use -
Me.SubmitButton.OnClientClick = "javascript:return confirm('You wish to do this?');"
False will halt the submit.
Regards,
Martin
Rgds, Martin.
For the benefit of all users please mark any post answers as appropriate.
Sorry Martin, i've already tried using 'OnClientClick' through the property of the button during design time and setting the property during runtime. While the confirm works fine, it breaks any validation controls on the page. This is the problem i'm having.
Sorry Martin, i've already tried using 'OnClientClick' through the property of the button during design time and setting the property during runtime. While the confirm works fine, it breaks any validation controls on the page. This is the problem i'm having.
Cheers.
What do you mean by breaks any validation controls? .
Which validation control is not working? Can you please explian little bit more.
Basically all the validation controls on the page will not fire if i set the OnClientClick property of the button with the javascript confirm method. When i comment out the OnClientClick propery and reload the page, validation works again.
Validation controls are called inside the page postback logic and as such should be getting called when you select yes with the confirm dialogue. However, if you select no then the validation will not be called. You could of course reverse engineer the validation
component of the postback and call the validation prior to the confirm prompt, but this is likely to be a fair bit of work.
If your page validation is not calling even after clicking yes in the confirm you have an error condition.
Rgds,
Martin.
Rgds, Martin.
For the benefit of all users please mark any post answers as appropriate.
lap993
Member
115 Points
23 Posts
asp:Button Validation with OnClientClick javascript - Not Validating
Feb 15, 2006 09:03 PM|LINK
Validation worked fine until I added a OnClientClick javascript to prompt the use to make sure they want to save the form data back to a sql database. Is my syntax worng or does the OnClientClick over ride the validation?
See below for my asp button control syntax
<asp:Button ID="btSaveForm" runat="server" Style="z-index: 138; left: 764px; position: absolute; top: 726px" Text="Save Form Data" Width="151px" CausesValidation="True" OnClientClick="javascript: return confirm('Are you sure you want to add this estimate data?')" />
budugu
All-Star
41186 Points
6033 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Feb 16, 2006 12:27 AM|LINK
Try this..
btSaveForm.Attributes.Add("OnClientClick", "if (! confirm(''Are you sure you want to add this estimate data??')) return;");
"Don't be afraid to be wrong; otherwise you'll never be right."
PLBlum
All-Star
30409 Points
5347 Posts
MVP
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Feb 16, 2006 03:16 PM|LINK
That's almost correct. Make sure that statement returns false.
if (! confirm('Are you sure you want to add this estimate data??')) return false;
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
xazos79
Member
138 Points
47 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 17, 2006 03:15 AM|LINK
Hi all,
Sorry to dredge this up from the dead, but i am unable to get this working with validation on my aspx pages. The following:
btnSaveCardHolder.Attributes.Add("OnClick", "if (! confirm('Are you sure you want to save the changes made to this card holder?')) return false;");
Gives me the confirmation dialog, but breaks validation. This:
btnSaveCardHolder.Attributes.Add("OnClientClick", "if (! confirm('Are you sure you want to save the changes made to this card holder?')) return false;");
Doesn't give me the dialog, and validation is fine. Is there a fix for this problem out there?
mokeefe
Star
10850 Points
2098 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 17, 2006 05:09 AM|LINK
Actually, there are some misnomers here.
OnClientclick is a server side attribute and as such adding it to a control in this mechanism is doing nothing other than invalidating the HTML control - non standard attribute in HTML.
For your requirements the following is applicable
In ASP.net 1.1 to execute client side script on the client click event you would use (note the casing) -
Me.SubmitButton.Attributes.Add("onclick", "javascript:return confirm('You wish to do this?")
In ASP.net 2.0 you would use -
Me.SubmitButton.OnClientClick = "javascript:return confirm('You wish to do this?');"
False will halt the submit.
Regards,
Martin
Martin.
For the benefit of all users please mark any post answers as appropriate.
mokeefe
Star
10850 Points
2098 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 17, 2006 05:09 AM|LINK
Martin.
For the benefit of all users please mark any post answers as appropriate.
xazos79
Member
138 Points
47 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 18, 2006 12:57 AM|LINK
Sorry Martin, i've already tried using 'OnClientClick' through the property of the button during design time and setting the property during runtime. While the confirm works fine, it breaks any validation controls on the page. This is the problem i'm having.
Cheers.
budugu
All-Star
41186 Points
6033 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 18, 2006 08:10 PM|LINK
Sorry Martin, i've already tried using 'OnClientClick' through the property of the button during design time and setting the property during runtime. While the confirm works fine, it breaks any validation controls on the page. This is the problem i'm having.
Cheers.
What do you mean by breaks any validation controls? .
Which validation control is not working? Can you please explian little bit more.
"Don't be afraid to be wrong; otherwise you'll never be right."
xazos79
Member
138 Points
47 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 19, 2006 03:21 AM|LINK
mokeefe
Star
10850 Points
2098 Posts
Re: asp:Button Validation with OnClientClick javascript - Not Validating
Oct 19, 2006 04:16 AM|LINK
Validation controls are called inside the page postback logic and as such should be getting called when you select yes with the confirm dialogue. However, if you select no then the validation will not be called. You could of course reverse engineer the validation component of the postback and call the validation prior to the confirm prompt, but this is likely to be a fair bit of work.
If your page validation is not calling even after clicking yes in the confirm you have an error condition.
Rgds,
Martin.
Martin.
For the benefit of all users please mark any post answers as appropriate.