473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

cannot find control within control

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");
Nov 19 '05 #1
4 4910
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" <db****@simnet.is> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
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");

Nov 19 '05 #2
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:O3**************@TK2MSFTNGP10.phx.gbl...
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" <db****@simnet.is> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
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");


Nov 19 '05 #3
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" <db****@simnet.is> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
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:O3**************@TK2MSFTNGP10.phx.gbl...
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" <db****@simnet.is> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
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");



Nov 19 '05 #4
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:%2****************@TK2MSFTNGP10.phx.gbl...
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" <db****@simnet.is> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
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:O3**************@TK2MSFTNGP10.phx.gbl...
> 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" <db****@simnet.is> wrote in message
> news:us**************@TK2MSFTNGP09.phx.gbl...
>> 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");
>>
>>
>
>



Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
0
by: bill yeager | last post by:
I have a datalist displaying parent information and a datagrid presenting child information. The data is being rendered just fine. The datagrid has template columns on it that I cannot gain access...
2
by: TM | last post by:
What is the method used to find all asp.net server controls (run at server) such as TextBox, ListBox, CheckBox... currently defined on an Asp.Net page at run time. I need it inside of a controlled...
2
by: Jim Lambert | last post by:
I have a form with custom controls. Each custom control contains a TextBox. When I attempt to dynamically add a CompareValidator to a TextBox which compares to a TextBox within the other custom...
8
by: Michael | last post by:
I am running a web server (IIS) on Windows 2003 SP 1. My ASP.NET C# applications run fine. However, my application is a combination of Classic ASP and C#. For some reason when you attempt to...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
8
by: wASP | last post by:
Hi, I'm having a problem referencing the elements within an object after a method of that object (a member function) has been activated with an onsubmit handler: - - - - - - - - ...
3
by: OJ | last post by:
Hi, I have added code to run on a button click event which adds usercontrols to an asp:Panel control held in a contentplaceholder defined by the masterpage. for (int x = 0; x <...
2
by: Bruce | last post by:
I am starting my first C## project. In one of my menu events I have the following: UserProfile winProfile = new UserProfile(); winProfile.Parent = this; winProfile.Show(); UserProfile is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.