Problems with Validator controls

  • Thread starter Thread starter John Holmes
  • Start date Start date
J

John Holmes

I'm using the RequiredFieldValidator on 9 text boxes and then a Validation
Summary control for bringing up a message when the user tries to click a
button that makes a trip to the server. This works fine on my development
machine, but when I copy the project to my test web server the required
validation doesn't occur and the summary dialog doesn't come up. The user is
allowed to click the button and it processes the event code on the server
just like there are no Required Field Validator controls. I'm not sure why
it would work on my machine, but not on the test web server. I think at one
point I had it working on the test web server, too. Any ideas for trying to
solve this will be much appreciated.

One other question about the Validator controls. Is there a way to suppress
the error messages from the individual controls and have the user just see
the summary dialog. That's what I'd really like. I don't like having to
provide real estate on my form for each field showing the errors.

Thanks,

John Holmes
(e-mail address removed)
 
Hi John,

Thanks for posting in the community!
From your description, you used RequiredFieldValidator controls and
ValidatioSummary control on a certain ASP.NET webpage to ensure the input
of some certain ASP.NET TEXTBOX server controls. However, you found the
validiton worked on your dev machine but not work on a test server machine
and also you wonder how to only show the validateSummary's message rather
than also display the individual required validator's message ,yes?

As for the first problem, I'd like to confirm on some further questions:
1. Are the RequiredValidators all set as EnableClientScript = true ? If so,
try set it as false to see whether the serverside validation work on both
machine.(I think it should work).

2. If # works , there seems have some problems with the ASP.NET buildin
clientside scripts on the test servermachine. Are the dotnet framework's
version same with the two machines? If so, I think you can try reinstalling
the ASP.NET buildin clientside script resources. Just open the Visual
Studio.net command prompt , througth the following steps:
Visual Studio.NET -->Visual Studio.NET tools --> Visual Studio.NET Command
prompt
Then in the command line window, type:
aspnet_regiis -c
this will reinstall the client-side scripts for ASP.NET, such as
client-side validation scripts, to the aspnet_client subdirectory of each
IIS site directory. For detailed info on the tool, you can view the
following reference in MSDN:

#ASP.NET IIS Registration Tool (Aspnet_regiis.exe)
http://msdn.microsoft.com/library/en-us/cptools/html/cpgrfASPNETIISRegistrat
ionToolAspnet_regiisexe.asp?frame=true

As for the second question --- only show the "validationSummary" control's
message, I think you can use the RequiredFieldValidator control's "Display"
property, try setting it to "none" in the propety window. Then, the
RequiredFieldvalidator's own error message won't be displayed.

Please check out the above suggestions. If you have any further questions
or new findings, please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Here's what I have found so far:

1. If I disable client scripting then validation doesn't work at all.
2. I enabled client scripting and then ran the aspnet_regiis.exe -c on the
test server and now validation works on that server.

This does concern me though, because it doesn't look like server side
validation is working. I have turned on viewstate for each of the validator
controls, but I'm not sure if I need that. I was thinking that I need it
turned on for server side validation to work. But as I said there's no
validation occurring when EnableClientScript is set to False.

Let me know if I need to do something to make server side validation work.

Thanks,

John Holmes
 
Hi John,

Thanks for your response and the further infos you provided. As you've
mentioned that the clientside validation works now but the serverside
validation not work if enableclientscript set as false, yes?

I'm not quite sure whether it's the certain page or still something wrong
with your server machine. Have you tried build another simple page to test
the RequiredFieldValidator?
Or if you can repro the problem via a simple page, would you please attache
the page to me so that I can do some further research on my side?

In addition, below is a test page I used on my side. Please also have a try
on it to see whether it works. Thanks.

-----------------------aspx page ----------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>RequiredField</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td colspan="2">
<asp:ValidationSummary id="vsMain"
runat="server"></asp:ValidationSummary>
</td>
</tr>
<tr>
<td>
Client Validation
</td>
<td>
Server Validation
</td>
</tr>
<tr>
<td>
txtOne:<asp:TextBox id="txtOne" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvOne" runat="server"
ErrorMessage="rfvOne" ControlToValidate="txtOne"
Display="None"></asp:RequiredFieldValidator>
</td>
<td>
txtTwo:<asp:TextBox id="txtTwo" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvTwo" runat="server"
ErrorMessage="rfvTwo" ControlToValidate="txtTwo" Display="None"
EnableClientScript="False"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
txtThree:<asp:TextBox id="txtThree" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvThree" runat="server"
ErrorMessage="rfvThree" ControlToValidate="txtThree"
Display="None"></asp:RequiredFieldValidator>
</td>
<td>
txtFour:<asp:TextBox id="txtFour" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvFour" runat="server"
ErrorMessage="rfvFour" ControlToValidate="txtFour" Display="None"
EnableClientScript="False"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button id="btnSubmit" runat="server" Text="Submit"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</HTML>

-------------------code behind page class------------
public class RequiredField : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ValidationSummary vsMain;
protected System.Web.UI.WebControls.TextBox txtThree;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvThree;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvOne;
protected System.Web.UI.WebControls.TextBox txtOne;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvFour;
protected System.Web.UI.WebControls.TextBox txtFour;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvTwo;
protected System.Web.UI.WebControls.TextBox txtTwo;
protected System.Web.UI.WebControls.Button btnSubmit;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Write("<br>Page is posted back at: " +
DateTime.Now.ToLongTimeString());
}
}


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top