Click here to Skip to main content
13,149,073 members (55,237 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys, got a problem with the standard validators in a project.

Basically I am adding the following to my form:

<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="MyGroup" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" EnableClientScript="true" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1" ValidationGroup="MyGroup"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="MyGroup" CausesValidation="true" onclick="Button1_Click" />

Problem is although the validation error displays, the page still posts back.

It is at this point i will say that if i put this in an .aspx page in the same project it works as it should.

However when i put it in a user control which is dynamically rendered, i get this problem.

The project does use URL rewriting as well, but im not sure that this is causing it. Any ideas?
Posted 13-Dec-12 1:25am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

As it turns out it was to do with the URL re-writing. I had Quickly implemented a custom form control off an MSDN article to combat the re-writing on the post back. What the control did was to remove the url from the action attribute, however it also removed the
on submit action.
So to solve the problem the following needs to be added to the RenderAttributes override in the custom control, should anyone else be using it.

if(this.Page.Validators != null && this.Page.Validators.Count >=1)
    writer.WriteAttribute("onsubmit", "javascript:return WebForm_OnSubmit();");

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

Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2017
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