problem with FindControl

Discussion in 'ASP .Net Web Controls' started by Terry, Feb 15, 2007.

  1. Terry

    Terry Guest

    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
    Terry, Feb 15, 2007
    #1
    1. Advertising

  2. Terry

    Teemu Keiski Guest

    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
    >
    >
    >
    Teemu Keiski, Feb 15, 2007
    #2
    1. Advertising

  3. Terry

    Terry Guest

    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:...
    > 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
    >>
    >>
    >>

    >
    Terry, Feb 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jaime

    FindControl problem

    Jaime, May 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    669
    Jaime
    May 20, 2005
  2. =?Utf-8?B?dHBhcmtzNjk=?=

    ItemCreated FindControl problem c#

    =?Utf-8?B?dHBhcmtzNjk=?=, Jun 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,505
    =?Utf-8?B?QkVMSVVT?=
    Jun 16, 2005
  3. Arjen

    Findcontrol problem

    Arjen, Oct 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,031
    Scott Allen
    Oct 18, 2005
  4. ThunderMusic
    Replies:
    2
    Views:
    410
    ThunderMusic
    Oct 9, 2006
  5. Terry

    problem with FindControl

    Terry, Feb 15, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    579
    Terry
    Feb 15, 2007
Loading...

Share This Page