Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot make a hidden textbox visible

Status
Not open for further replies.

qwe1204

Programmer
Aug 30, 2001
21
GB
I have a label and a textbox in a panel on my form. In the form load event I can set the visiblity property to false, but on postback I want to set the visibility to true but I get the error

Unable to find control with id 'TextBox2' that is associated with the Label 'LabelTextBox2'

even when I display the textbox first and then the label. It seems to do this when my end label tag is after my end textbox tag but I want to format it this way to make the styling of the page easier. Anybody got any ideas how I can do this?
 
I don't really understand. Can you post an example of your HTML and code and show what doesn't work?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here is my HTML

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
&nbsp;<asp:panel ID="Panel1" runat="server" Height="50px" Width="125px">
<fieldset><legend><span>Customer 1 Personal Details</span></legend>
<asp:Label ID="Label1" runat="server" AssociatedControlID="TextBox1" Text="Label 1"><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="textbox1" EnableClientScript="false"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" enableclientscript="true" ControlToValidate="textbox1" ValidationExpression="^[a-zA-Z ]*$"></asp:RegularExpressionValidator></asp:Label>
<asp:Label ID="LabelTextBox2" runat="server" AssociatedControlID="TextBox2" Text="Label 2"><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:Label>
<asp:Label ID="Label3" runat="server" AssociatedControlID="TextBox3" Text="Label 3"><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="textbox3" EnableClientScript="false"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="RegularExpressionValidator" enableclientscript="False" ControlToValidate="textbox3" ValidationExpression="^[a-zA-Z ]*$"></asp:RegularExpressionValidator></asp:Label>
</fieldset>
</asp:panel>
<asp:panel ID="Panel2" runat="server" Height="50px" Width="125px">
<fieldset><legend><span>Customer 1 Personal Details</span></legend>
<asp:Label ID="Label4" runat="server" AssociatedControlID="TextBox4" Text="Label 4"><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></asp:Label>
<asp:Label ID="Label5" runat="server" AssociatedControlID="TextBox5" Text="Label 5"><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></asp:Label>
<asp:Label ID="Label6" runat="server" AssociatedControlID="TextBox6" Text="Label 6"><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></asp:Label>
</fieldset>
</asp:panel>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>


and this is my page load event



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Page.IsPostBack Then
TextBox2.Visible = True
LabelTextBox2.Visible = True
Else
TextBox2.Visible = False
LabelTextBox2.Visible = False
End If

End Sub
 
OK, I think it's probably a combination of your nested TextBox's (i.e. they are inside a Label control) and trying to set the AssociatedControlID for those Labels.

Try this instead:
Code:
...
<body>
    <form id="form1" runat="server">

        <asp:Label ID="LabelTextBox2" runat="server" AssociatedControlID="TextBox2" Text="Label 2"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
</body>
...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top