Ok Simple : TextBox, RequiredFieldValidator, Button
Without a Master Page – if the TextBox is empty – I get an Error Message when Clicking Button.
With a Master Page – if the TextBox is empty – I get NO Error Message when Clicking Button.
This happened recently without changing the code. Simply creating a DEFAULT Master Page and putting these three controls in it will result in NOT having an Error Message.
I am at a loss on how to fix this. It seems not code-related as a default Master Page stops the error message from showing up.
Should I reinstall Visual Studio 2010 Ultimate?
Browser Independent, Recent, Not Code Related AFAIK, just started happening recently.
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Button ID="Button1"
runat="server" Text="Button" onclick="Button1_Click"
ValidationGroup="RequiredFieldValidator1" />
</asp:ContentPlaceHolder>
</div>
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
I think you’re experiencing the problem because you have the validation group set for your button, however, it is not set for the TextBox and the Validator control itself.
Try to assign the same ValidationGroup for all controls that are participating in your validation scenario. It seems that you have misused the
Property. You don’t have to use the Id of the RequiredFieldValidator as your button’s ValidationGroup (you can, but you don’t have to). Please refer to the following article for more details:
http://msdn.microsoft.com/en-us/library/ms227424%28v=vs.100%29.aspx
Anyway, the
property has to be the same for all controls that belong to your validation scenario. In your case this is TextBox, Button and the Validator control.