Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2009, 09:55 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default 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"/>&nbsp;<asp:Button
ID="Statusbtn"runat="server"OnClick="Statusbtn_Click"Text="Status Updates"/>&nbsp;<asp:Button
ID="Linksbtn"runat="server"OnClick="Linksbtn_Click"Text="Links"/>&nbsp;
<asp:ButtonID="Photosbtn"runat="server"OnClick="Photosbtn_Click"Text="Photos"/>&nbsp;
<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;<asp:ButtonID="NotePost"runat="server"OnClick="NotePost_Click"Text="Post"Visible="true"/>&nbsp;<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<asp:ButtonID="StatusPost"runat="server"OnClick="StatusPost_Click"Text="Comment"/>&nbsp;<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<asp:ButtonID="LinkPost"runat="server"OnClick="LinkPost_Click"Text="Comment"/>&nbsp;<br/><br/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<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"/>&nbsp;
<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..
 
Old March 12th, 2009, 10:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

yep.. you have to do a findcontrol for the gridview (now you are doing it for the page). In fact, you have to do a findcontrol for the row in the grid that you want to search the button.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old March 12th, 2009, 10:25 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

But hey, it appears the below error. And i dont really understand what it really means..

Object reference not set to an instance of an object.

 
Old March 12th, 2009, 10:38 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

protectedvoid Commentbtn_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
TextBox textBox = (TextBox)row.FindControl("Notestxtbox");
textBox.Visible =
true;
Button thisButton = (Button)row.FindControl("NotePost");
thisButton.Visible =
true;
}
}

I have edited my codes in this way. now all errors are solved. but however, the textBox and button doesn't appear...
what really happens





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to fetch textbox values triveni_sh BOOK: Professional Crystal Reports for VS.NET 0 January 5th, 2006 01:28 AM
FindControl Wervis C# 7 November 30th, 2005 09:51 AM
FindControl dkr72 Excel VBA 0 January 19th, 2005 09:55 AM
unable to display stored data in textbox(asp.net) Abhinav_jain_mca ADO.NET 6 August 4th, 2004 07:45 AM
unable to print stored data in textbox(asp.net) Abhinav_jain_mca ADO.NET 1 July 30th, 2004 09:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.