Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > problem with FindControl

Reply
Thread Tools

problem with FindControl

 
 
Terry
Guest
Posts: n/a
 
      02-15-2007
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



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      02-15-2007
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" <> wrote in message
news:...
> 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
>
>
>


 
Reply With Quote
 
 
 
 
Terry
Guest
Posts: n/a
 
      02-15-2007
Thanks, it works indeed ...
Maybe you can also help me with the other problem in the thread above "how
to trigger .."?

"Teemu Keiski" <> schreef in bericht
news:F71CEBC9-B5A2-4BFA-819C-...
> 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" <> wrote in message
> news:...
>> 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
>>
>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with FindControl Terry ASP .Net 2 02-15-2007 10:02 AM
WebControls and sub controls... problem with FindControl... Why? ThunderMusic ASP .Net 2 10-09-2006 04:26 AM
Findcontrol problem Arjen ASP .Net 2 10-18-2005 02:42 PM
ItemCreated FindControl problem c# =?Utf-8?B?dHBhcmtzNjk=?= ASP .Net 2 06-16-2005 05:11 PM
FindControl problem Jaime ASP .Net 0 05-20-2005 06:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57