Unable to FindControl for Textbox
Hello pple. my textbox are inside a gridview and i am unable to find it. What i wanna do is, when i click on the button, i want a textbox and another button to appear. That is why i can't locate it... Is there anything wrong with my codes?
Source Code
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptlanguage="javascript"type="text/javascript">
// <!CDATA[
// ]]>
</script>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ButtonID="Notebtn"runat="server"OnClick="Notebtn_Click"Text="Notes"/> <asp:Button
ID="Statusbtn"runat="server"OnClick="Statusbtn_Click"Text="Status Updates"/> <asp:Button
ID="Linksbtn"runat="server"OnClick="Linksbtn_Click"Text="Links"/>
<asp:ButtonID="Photosbtn"runat="server"OnClick="Photosbtn_Click"Text="Photos"/>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"BorderStyle="None"Height="0px"Width="355px"GridLines="None">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("FullName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<ahref=""><asp:LabelID="Label1"runat="server"Text='<%# Bind("FullName") %>'></asp:Label></a> wrote a note.<br/><br/>
<asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label><br/><br/><asp:ButtonID="Commentbtn"runat="server"Text="Comment"OnClick="Commentbtn_Click"/><asp:TextBoxID="Notestxtbox"runat="server"Columns="36"TextMode="MultiLine"MaxLength="100"Height="60px"Width="304px"Visible="false"></asp:TextBox>
&n bsp; &nbs p;
&n bsp; &nbs p;
&n bsp; &nbs p;   ;<asp:ButtonID="NotePost"runat="server"OnClick="NotePost_Click"Text="Post"Visible="true"/> <br/><br/>
</ItemTemplate>
</asp:TemplateField></Columns>
</asp:GridView><asp:GridViewID="GridView2"runat="server"AutoGenerateColumns="False"Height="0px"Width="357px"BorderStyle="None"GridLines="None">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("FullName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<ahref=""><asp:LabelID="Label1"runat="server"Text='<%# Bind("FullName") %>'></asp:Label></a>
<asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label>.<br/><br/>
<asp:TextBoxID="Statustxtbox"runat="server"Columns="36"TextMode="MultiLine"MaxLength="100"Height="60px"Width="304px"></asp:TextBox>
&n bsp; &nbs p;
&n bsp; &nbs p;
&n bsp;  
<asp:ButtonID="StatusPost"runat="server"OnClick="StatusPost_Click"Text="Comment"/> <br/><br/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:GridViewID="GridView3"runat="server"AutoGenerateColumns="False"Height="0px"Width="363px"BorderStyle="None"GridLines="None">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("FullName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<ahref=""><asp:LabelID="Label1"runat="server"Text='<%# Bind("FullName") %>'></asp:Label></a> posted a new link.<br/><br/>
<asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label><br/><br/>
<asp:TextBoxID="Linktxtbox"runat="server"Columns="36"TextMode="MultiLine"MaxLength="100"Height="60px"Width="304px"></asp:TextBox>
&n bsp; &nbs p;
&n bsp; &nbs p;
&n bsp;  
<asp:ButtonID="LinkPost"runat="server"OnClick="LinkPost_Click"Text="Comment"/> <br/><br/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LabelID="UpdateIDlbl"runat="server"Visible="False"></asp:Label>
<asp:LabelID="Emaillbl"runat="server"Visible="False"></asp:Label>
<asp:LabelID="Textinput"runat="server"Visible="False"/>
<br/>
</div>
</form>
</body>
</html>
CS Code
protectedvoid Commentbtn_Click(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)FindControl("Notestxtbox") asTextBox;
TextBox1.Visible = true;
}
}
Last edited by julius; March 12th, 2009 at 10:08 PM..
|