Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi guys, got a problem with the standard asp.net 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 2:25am

1 solution

Rate this: bad
good
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();");
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
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