Hidden Validators Cause Javascript Error

  • Thread starter news.microsoft.com
  • Start date
N

news.microsoft.com

I am going crazy trying to figure this out, and I am wondering if this is a
bug in the ASP.Net implementation.

My situation:

I have an ASPX page with 2 different modes:

*Mode 1: Datagrid with no footer
*Mode 2: Datagrid with a footer template containing a textbox and an "Add
Record" command (also has an edit column)

Everything works fine until I put a RequiredFieldValidator in the
FooterTemplate. Doing so causes the following Javascript error:
'Page_Validators' is undefined. I believe this is happening because I am
dynamically showing / hiding the footer in my code-behind, depending on a
selected dropdown value within the page.

Is there a workaround / solution for this?

Footer Template snippet:

<FooterTemplate>
<asp:LinkButton CommandName="AddNewRecord" Text="Add Custom Threshold"
ID="lnkAddThreshold" Runat="server"/>
<asp:RequiredFieldValidator ID="reqDdThresholdUpperAddNew"
ControlToValidate="txtDdThresholdUpperAddNew" ErrorMessage="Please enter a
value" Display="Dynamic" Visible="True" Runat="server"/>
</FooterTemplate>

Code Behind snippet:

protected void BindGrid()
{
//Set each grid's datasource and bind to it
dgDDThresholdData.DataSource=DataAccess.clsCommonAccess.getDBValues();
dgDDThresholdData.DataBind();

//If we are showing a custom version of the form, then allow
editing/adding/deleting of values
if(Convert.ToInt32(intThresholdTypeID)==2)
{
dgDDThresholdData.Columns[6].Visible=true; //show the edit column
dgDDThresholdData.Columns[7].Visible=true; //show the delete column
dgDDThresholdData.ShowFooter = true; //show the footer (add new
record)
}
else
{
dgDDThresholdData.Columns[6].Visible=false; //hide the edit column
dgDDThresholdData.Columns[7].Visible=false; //hide the delete column
dgDDThresholdData.ShowFooter = false; //hide the footer (add new
record)
}
}


Any ideas?
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top