Connecting Tech Pros Worldwide Help | Site Map

problem with FindControl

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 15th, 2007, 07:55 AM
Terry
Guest
 
Posts: n/a
Default problem with FindControl

Hi,

i want to access control "TextBox1" embedded in another control "LoginView1"
in order to change the 'Text' of the textbox.

Therefore i use 'FindControl' method but i get error:
"Object reference not set to an instance of an object" on line: tb =
lv.FindControl("textbox1")


Thanks for help
Cliff


aspx:
----
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<table>
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<fieldset style="height: 425px; width: 335px;">
<tr><td>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
</td></tr>
</fieldset>
</LoggedInTemplate>
</asp:LoginView>
</table>
</asp:Content>

code-behind:
-----------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim lv As LoginView
Dim tb As TextBox
lv = FindControl("loginview1")
tb = lv.FindControl("textbox1")
tb.Text = "ok"
end sub




  #2  
Old February 15th, 2007, 08:45 AM
Teemu Keiski
Guest
 
Posts: n/a
Default Re: problem with FindControl

If you are running this on the content page, you don't need tom FindControl
the LoginView. You can just

Dim tb As TextBox
tb = Me.LoginView1.FindControl("textbox1")
tb.Text = "ok"

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net





"Terry" <no@mail.prwrote in message
news:eUnDZyNUHHA.4668@TK2MSFTNGP04.phx.gbl...
Quote:
Hi,
>
i want to access control "TextBox1" embedded in another control
"LoginView1" in order to change the 'Text' of the textbox.
>
Therefore i use 'FindControl' method but i get error:
"Object reference not set to an instance of an object" on line: tb =
lv.FindControl("textbox1")
>
>
Thanks for help
Cliff
>
>
aspx:
----
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<table>
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<fieldset style="height: 425px; width: 335px;">
<tr><td>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
</td></tr>
</fieldset>
</LoggedInTemplate>
</asp:LoginView>
</table>
</asp:Content>
>
code-behind:
-----------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim lv As LoginView
Dim tb As TextBox
lv = FindControl("loginview1")
tb = lv.FindControl("textbox1")
tb.Text = "ok"
end sub
>
>
>
  #3  
Old February 15th, 2007, 09:15 AM
Terry
Guest
 
Posts: n/a
Default Re: problem with FindControl

Thanks, it works indeed ...
Maybe you can also help me with the other problem in the thread above "how
to trigger .."?

"Teemu Keiski" <joteke@aspalliance.comschreef in bericht
news:F71CEBC9-B5A2-4BFA-819C-A88BB87BE5EA@microsoft.com...
Quote:
If you are running this on the content page, you don't need tom
FindControl the LoginView. You can just
>
Dim tb As TextBox
tb = Me.LoginView1.FindControl("textbox1")
tb.Text = "ok"
>
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
>
>
>
>
>
"Terry" <no@mail.prwrote in message
news:eUnDZyNUHHA.4668@TK2MSFTNGP04.phx.gbl...
Quote:
>Hi,
>>
>i want to access control "TextBox1" embedded in another control
>"LoginView1" in order to change the 'Text' of the textbox.
>>
>Therefore i use 'FindControl' method but i get error:
>"Object reference not set to an instance of an object" on line: tb =
>lv.FindControl("textbox1")
>>
>>
>Thanks for help
>Cliff
>>
>>
>aspx:
>----
><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
>Runat="Server">
><table>
><asp:LoginView ID="LoginView1" runat="server">
><LoggedInTemplate>
><fieldset style="height: 425px; width: 335px;">
><tr><td>
><asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
></td></tr>
></fieldset>
></LoggedInTemplate>
></asp:LoginView>
></table>
></asp:Content>
>>
>code-behind:
>-----------
>Private Sub Page_Load(ByVal sender As Object, ByVal e As
>System.EventArgs) Handles Me.Load
>Dim lv As LoginView
> Dim tb As TextBox
> lv = FindControl("loginview1")
> tb = lv.FindControl("textbox1")
> tb.Text = "ok"
>end sub
>>
>>
>>
>

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.