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 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.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