[thelist] RE: asp.net: Why won't InitialValue work

Robert Vreeland vreeland at studioframework.com
Thu Dec 23 23:33:50 CST 2004


Ok, Do you have a IsPostBack handler in your script? And do you call
Validate() in it? The following code worked as expected:
<%@ page language="c#" runat="server" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e){
 if(IsPostBack){
  Validate();
  if(Page.IsValid){
   Response.Redirect("blank.html");
  }
  else{
   errorMsg.Text = "";
  }
 }
 else{
  errorMsg.Text = "";
 }
}
</script>
<html>
<head>
<title>Test </title>
</head>
<body>
<form runat="server">
<asp:label id="errorMsg" runat="server" />
<asp:TextBox id="joined" runat="server" />
<asp:RequiredFieldValidator id="rfvJoined"
 EnableClientScript="true"
 ControlToValidate="joined"
 ErrorMessage="Required Field:"
 runat="server" />
<asp:RegularExpressionValidator id="revJoined"
 ControlToValidate="joined"
 EnableClientScript="true"
 ErrorMessage=" Should be in format MM-DD-YY"
 ValidationExpression="^\d\d-\d\d-\d\d$"
 runat="server" />
<asp:Button runat="server" text="Submit" />

</form>
</body>
</html>
Note, EnableClientScript="true". As mentioned in my earlier post, it is used
by IE 5.5+.
Hope this is more helpful
Robert Vreeland
Managing Partner
StudioFramework
508 965 5819
vreeland at studioframework.com
----- Original Message ----- 
From: "Casey Crookston" <casey at thecrookstons.com>
To: <thelist at lists.evolt.org>
Sent: Wednesday, December 22, 2004 10:44 PM
Subject: Re: [thelist] RE: asp.net: Why won't InitialValue work


> > ASP RegularExpressionValidator control will validate on the client if it
> is
> > an 'uplevel' browser - IE 5.5+, all other browsers will post back for
> > validation on the server.
>
>
> Thanks, but this doesn't help me solve the problem at all.  I would like
to
> offer the user an example of how the date format should be, and make it a
> required field, and validate the format.  My question is, how come when I
> use InitialValue in the RequiredFieldValidator does it no longer make it a
> required field?  The original post is below.
>
> Thanks,
>
> Casey
>
> > If I include InitialValue="MM-DD-YYYY" in the
> > RegularExpressionValidator,
> > nothing happens... it's like it's not even there.  If I include it in
> > the
> > RequiredFieldValidator, it also does not display the initial value, AND
> > the
> > validator stops working and allows an empty value.  What's with that?
> > How
> > can I make this work?
> >
> > <form runat="server">
> >
> > <asp:textbox id="joined" runat="server" />
> >
> > <asp:RegularExpressionValidator id="revJoined"
> > ControlToValidate="joined"
> > ErrorMessage="Formt: Enter Date: MM-DD-YYYY"  Display="Dynamic"
> > ValidationExpression="\d{2}-\d{2}-\d{4}" runat="server" />
> >
> > <asp:RequiredFieldValidator id="rfvJoined" ControlToValidate="joined"
> > ErrorMessage="Required: Enter Date: MM-DD-YYYY" Display="Dynamic"
> > runat="server" />
> >
> > </form>
>
>
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !



More information about the thelist mailing list