Hidden Panel with a ListBox and RequiredFieldValidator breaks page



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

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://

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></

<asp:panel ID="pnlPanel1" runat="server" Style="display:
<asp:ListBox ID="lbxPicker" runat="Server"
<asp:ListItem Text="Chocolate" Value="C"></
<asp:ListItem Text="Vanilla" Value="V"></asp:ListItem>
<asp:ListItem Text="Rocky Road" Value="R"></
<asp:ListItem Text="Other" Value="O"></asp:ListItem>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="lbxPicker" Display="Dynamic"
ErrorMessage="You must choose at least one flavor"></

<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" />
<asp:Label ID="lblInfo" runat="server" Text=""></asp:Label>

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 " +


BTW...I know that changing my panel to Visible = "False" would fix the
problem. But assuming that the constraints of the app say that I need
to use display:none, is there a way to make this work?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question