cannot find control within control

Discussion in 'ASP .Net' started by Daves, Apr 12, 2005.

  1. Daves

    Daves Guest

    hi,
    sorry for re-posting but it's a simple question and ought to have a very
    simple solution; I am trying to use Findcontrol to grab a Button control
    within a Formview control:

    <form ID="Form1" runat="server">
    <asp:FormView ID="FormView1" Runat="server">
    <ItemTemplate>
    <asp:Button ID="Button1" runat="server" Text="Breyta" CommandName="Edit"/>
    ...

    This is what won't work:
    Button Button1 = (Button) FormView1.FindControl("Button1");
     
    Daves, Apr 12, 2005
    #1
    1. Advertising

  2. Daves

    Karl Seguin Guest

    Being too lazy to load up VWD, try using:
    FormView1.Row.FindControl("Button1")

    In a repeater, you'd have multiple "Button1"'s and would need to look at
    repeater.Items.FindControl

    FormViews are the same..though there's only 1 row...so it's exposed as Row
    (if I remember correctly).

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Daves" <> wrote in message
    news:...
    > hi,
    > sorry for re-posting but it's a simple question and ought to have a very
    > simple solution; I am trying to use Findcontrol to grab a Button control
    > within a Formview control:
    >
    > <form ID="Form1" runat="server">
    > <asp:FormView ID="FormView1" Runat="server">
    > <ItemTemplate>
    > <asp:Button ID="Button1" runat="server" Text="Breyta"

    CommandName="Edit"/>
    > ...
    >
    > This is what won't work:
    > Button Button1 = (Button) FormView1.FindControl("Button1");
    >
    >
     
    Karl Seguin, Apr 12, 2005
    #2
    1. Advertising

  3. Daves

    Daves Guest

    thx Karl, tried that and bloody error "Object reference not set to an
    instance of an object."
    Button Button1 = (Button) FormView1.Row.FindControl("Button1");


    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > Being too lazy to load up VWD, try using:
    > FormView1.Row.FindControl("Button1")
    >
    > In a repeater, you'd have multiple "Button1"'s and would need to look at
    > repeater.Items.FindControl
    >
    > FormViews are the same..though there's only 1 row...so it's exposed as Row
    > (if I remember correctly).
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Daves" <> wrote in message
    > news:...
    >> hi,
    >> sorry for re-posting but it's a simple question and ought to have a very
    >> simple solution; I am trying to use Findcontrol to grab a Button control
    >> within a Formview control:
    >>
    >> <form ID="Form1" runat="server">
    >> <asp:FormView ID="FormView1" Runat="server">
    >> <ItemTemplate>
    >> <asp:Button ID="Button1" runat="server" Text="Breyta"

    > CommandName="Edit"/>
    >> ...
    >>
    >> This is what won't work:
    >> Button Button1 = (Button) FormView1.FindControl("Button1");
    >>
    >>

    >
    >
     
    Daves, Apr 12, 2005
    #3
  4. Daves

    Karl Seguin Guest

    i started it up and it worked fine for me...as you sure you are calling
    DataBind on the FormView? Are you sure the datasource has an entry in it?

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Daves" <> wrote in message
    news:...
    > thx Karl, tried that and bloody error "Object reference not set to an
    > instance of an object."
    > Button Button1 = (Button) FormView1.Row.FindControl("Button1");
    >
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:...
    > > Being too lazy to load up VWD, try using:
    > > FormView1.Row.FindControl("Button1")
    > >
    > > In a repeater, you'd have multiple "Button1"'s and would need to look at
    > > repeater.Items.FindControl
    > >
    > > FormViews are the same..though there's only 1 row...so it's exposed as

    Row
    > > (if I remember correctly).
    > >
    > > Karl
    > >
    > > --
    > > MY ASP.Net tutorials
    > > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > > annoying)
    > > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > > come!)
    > > "Daves" <> wrote in message
    > > news:...
    > >> hi,
    > >> sorry for re-posting but it's a simple question and ought to have a

    very
    > >> simple solution; I am trying to use Findcontrol to grab a Button

    control
    > >> within a Formview control:
    > >>
    > >> <form ID="Form1" runat="server">
    > >> <asp:FormView ID="FormView1" Runat="server">
    > >> <ItemTemplate>
    > >> <asp:Button ID="Button1" runat="server" Text="Breyta"

    > > CommandName="Edit"/>
    > >> ...
    > >>
    > >> This is what won't work:
    > >> Button Button1 = (Button) FormView1.FindControl("Button1");
    > >>
    > >>

    > >
    > >

    >
    >
     
    Karl Seguin, Apr 12, 2005
    #4
  5. Daves

    Daves Guest

    Databind() did it...
    which I still don't understand! There was an entry in it without doing
    databind, could it be that Databind is done later in the event flow?

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:%...
    >i started it up and it worked fine for me...as you sure you are calling
    > DataBind on the FormView? Are you sure the datasource has an entry in it?
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Daves" <> wrote in message
    > news:...
    >> thx Karl, tried that and bloody error "Object reference not set to an
    >> instance of an object."
    >> Button Button1 = (Button) FormView1.Row.FindControl("Button1");
    >>
    >>
    >> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    >> wrote in message news:...
    >> > Being too lazy to load up VWD, try using:
    >> > FormView1.Row.FindControl("Button1")
    >> >
    >> > In a repeater, you'd have multiple "Button1"'s and would need to look
    >> > at
    >> > repeater.Items.FindControl
    >> >
    >> > FormViews are the same..though there's only 1 row...so it's exposed as

    > Row
    >> > (if I remember correctly).
    >> >
    >> > Karl
    >> >
    >> > --
    >> > MY ASP.Net tutorials
    >> > http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> > annoying)
    >> > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> > come!)
    >> > "Daves" <> wrote in message
    >> > news:...
    >> >> hi,
    >> >> sorry for re-posting but it's a simple question and ought to have a

    > very
    >> >> simple solution; I am trying to use Findcontrol to grab a Button

    > control
    >> >> within a Formview control:
    >> >>
    >> >> <form ID="Form1" runat="server">
    >> >> <asp:FormView ID="FormView1" Runat="server">
    >> >> <ItemTemplate>
    >> >> <asp:Button ID="Button1" runat="server" Text="Breyta"
    >> > CommandName="Edit"/>
    >> >> ...
    >> >>
    >> >> This is what won't work:
    >> >> Button Button1 = (Button) FormView1.FindControl("Button1");
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Daves, Apr 12, 2005
    #5
  6. Daves

    topherzee

    Joined:
    Sep 10, 2008
    Messages:
    2
    Soution to formview findcontrol problem

    None of the above suggestions worked for me.
    What did work was when I moved the call to the DataBound event.
    In VB..

    Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim txtUserID As TextBox = FormView1.FindControl("user_idTextBox")
    txtUserID.Text = 34

    -topherzee
     
    topherzee, Sep 10, 2008
    #6
    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. KatB
    Replies:
    0
    Views:
    467
  2. =?Utf-8?B?RQ==?=
    Replies:
    0
    Views:
    457
    =?Utf-8?B?RQ==?=
    Sep 11, 2007
  3. Wybo Dekker
    Replies:
    1
    Views:
    398
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    440
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    868
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page