Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cannot find control within control

Reply
Thread Tools

cannot find control within control

 
 
Daves
Guest
Posts: n/a
 
      04-12-2005
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");


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      04-12-2005
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[i].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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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");
>
>



 
Reply With Quote
 
 
 
 
Daves
Guest
Posts: n/a
 
      04-12-2005
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:(E-Mail Removed)...
> 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[i].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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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");
>>
>>

>
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      04-12-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > 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[i].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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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");
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Daves
Guest
Posts: n/a
 
      04-12-2005
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:%(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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:(E-Mail Removed)...
>> > 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[i].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" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> 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");
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
topherzee topherzee is offline
Junior Member
Join Date: Sep 2008
Posts: 2
 
      09-09-2008
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
 
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
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Cannot upgrade Google Earth cannot find {18D3ED9E-183C-4C00-B333-FB0C2FAE8B0F} joewo Computer Support 3 10-09-2007 05:23 AM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
Browser cannot find any server anymore after 5 minutes of normal activity (" The page cannot be displayed ") reply@newsgroup.please Computer Support 6 01-05-2004 04:03 AM



Advertisments