E
EvanM
I encountered this problem in an application that I'm currently
developing. I've re-produced the problem in a simple demo. If you
have a ListBox field and validate that a selection is made using a
RequiredFieldValidator, and then wrap the controls in a Panel with the
style set to display:none, all post backs on the page break.
See the following example. I have a Panel which is hidden using the
style tag. Inside of the panel are my listbox and validator
controls. Outside of the panel i have a button and a label. When the
button is pushed, the screen should post back and set the text of the
label. However, because of the RequiredFieldValidator in my hidden
panel - the post back never occurs. If you were to remove the
RequiredFieldValidator from the aspx page, the postback would occur
normally.
CONTENTS OF Default2.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></
asp:ScriptManager>
<aspanel ID="pnlPanel1" runat="server" Style="display:
none;">
<asp:ListBox ID="lbxPicker" runat="Server"
SelectionMode="Multiple">
<asp:ListItem Text="Chocolate" Value="C"></
asp:ListItem>
<asp:ListItem Text="Vanilla" Value="V"></asp:ListItem>
<asp:ListItem Text="Rocky Road" Value="R"></
asp:ListItem>
<asp:ListItem Text="Other" Value="O"></asp:ListItem>
</asp:ListBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="Server"
ControlToValidate="lbxPicker" Display="Dynamic"
ErrorMessage="You must choose at least one flavor"></
asp:RequiredFieldValidator>
</aspanel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<asp:Label ID="lblInfo" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
CONTENTS OF Default2.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblInfo.Text = "You pressed the button at " +
DateTime.Now.ToShortTimeString();
}
}
developing. I've re-produced the problem in a simple demo. If you
have a ListBox field and validate that a selection is made using a
RequiredFieldValidator, and then wrap the controls in a Panel with the
style set to display:none, all post backs on the page break.
See the following example. I have a Panel which is hidden using the
style tag. Inside of the panel are my listbox and validator
controls. Outside of the panel i have a button and a label. When the
button is pushed, the screen should post back and set the text of the
label. However, because of the RequiredFieldValidator in my hidden
panel - the post back never occurs. If you were to remove the
RequiredFieldValidator from the aspx page, the postback would occur
normally.
CONTENTS OF Default2.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></
asp:ScriptManager>
<aspanel ID="pnlPanel1" runat="server" Style="display:
none;">
<asp:ListBox ID="lbxPicker" runat="Server"
SelectionMode="Multiple">
<asp:ListItem Text="Chocolate" Value="C"></
asp:ListItem>
<asp:ListItem Text="Vanilla" Value="V"></asp:ListItem>
<asp:ListItem Text="Rocky Road" Value="R"></
asp:ListItem>
<asp:ListItem Text="Other" Value="O"></asp:ListItem>
</asp:ListBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="Server"
ControlToValidate="lbxPicker" Display="Dynamic"
ErrorMessage="You must choose at least one flavor"></
asp:RequiredFieldValidator>
</aspanel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<asp:Label ID="lblInfo" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
CONTENTS OF Default2.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblInfo.Text = "You pressed the button at " +
DateTime.Now.ToShortTimeString();
}
}