473,387 Members | 1,493 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,387 software developers and data experts.

Page.Controls(0).FindControl("tbxCompetitor01Produ ct")

Hello,

I am looping through each control using the following to find a particular
control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product").

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"
For Each ctlMaster As Control In Page.Controls ' Page
If TypeOf ctlMaster Is MasterPage Then '
MasterPage
For Each ctlForm As Control In ctlMaster.Controls
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Controls
If TypeOf ctlContent Is ContentPlaceHolder Then
'ContentPlaceHolder
For Each ctlChild As Control In ctlContent.Controls

If TypeOf ctlChild Is TextBox Then
If ctlChild.ID = strFindCtl Then strSubmitter &=
CType(ctlChild, TextBox).Text & ", "
End If

Next
End If
Next
End If
Next
End If
Next
Next


Based on the article
(http://dotnetjunkies.com/WebLog/jpal...01/23919.aspx), I
am trying to follow the format for the following in order to reduce my code:
(MyUserControl)Page.Controls[0].FindControl(ā€¯ucMyUserControlā€¯);

However, when I use the following:

Dim ctlSteven As Control =
Page.Controls(0).FindControl("tbxCompetitor01Produ ct")
Response.Write(ctlSteven.ID)

I get the error:
I get the error: System.NullReferenceException: Object reference not set to
an instance of an object.

Any help with this would be appreciated.
--
Thanks in advance,
sck10
Nov 18 '05 #1
2 3881
Hi sck10:

You have to be aware of 'naming containers' when using FindControl.
You'll need to invoke FindControl on the ContentPlaceHolder instance.

For an example of what I mean, see my article:
In Search Of ASP.Net Controls
http://odetocode.com/Articles/116.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 28 Sep 2004 08:01:04 -0700, "sck10" <sc***@online.nospam>
wrote:
Hello,

I am looping through each control using the following to find a particular
control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product").

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"
For Each ctlMaster As Control In Page.Controls ' Page
If TypeOf ctlMaster Is MasterPage Then '
MasterPage
For Each ctlForm As Control In ctlMaster.Controls
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Controls
If TypeOf ctlContent Is ContentPlaceHolder Then
'ContentPlaceHolder
For Each ctlChild As Control In ctlContent.Controls

If TypeOf ctlChild Is TextBox Then
If ctlChild.ID = strFindCtl Then strSubmitter &=
CType(ctlChild, TextBox).Text & ", "
End If

Next
End If
Next
End If
Next
End If
Next
Next


Based on the article
(http://dotnetjunkies.com/WebLog/jpal...01/23919.aspx), I
am trying to follow the format for the following in order to reduce my code:
(MyUserControl)Page.Controls[0].FindControl(”ucMyUserControl”);

However, when I use the following:

Dim ctlSteven As Control =
Page.Controls(0).FindControl("tbxCompetitor01Prod uct")
Response.Write(ctlSteven.ID)

I get the error:
I get the error: System.NullReferenceException: Object reference not set to
an instance of an object.

Any help with this would be appreciated.


Nov 18 '05 #2
Hi Scott,

For my loop, I referenced the contentplaceholder on the master page as you
suggested (and it works!). One thing I ran into is that I was unable to
figure out how to reference the the "Content" control (id="Content1") on the
content page or if I even need too. Thanks again for your help...

This is on the master page:
<asp:ContentPlaceHolder ID="cphMainContent"
Runat="server"></asp:ContentPlaceHolder>

Is on the content page:
<asp:Content ID="Content1" ContentPlaceHolderID="cphMainContent"
Runat="server">

This works...
For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"
ctlFind = Master.FindControl("cphMainContent").FindControl(s trFindCtl)
strFrmObj = CType(ctlFind, TextBox).Text & "<br>"
Response.Write(strFindCtl & " = " & strFrmObj)
Next

"Scott Allen" wrote:
Hi sck10:

You have to be aware of 'naming containers' when using FindControl.
You'll need to invoke FindControl on the ContentPlaceHolder instance.

For an example of what I mean, see my article:
In Search Of ASP.Net Controls
http://odetocode.com/Articles/116.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 28 Sep 2004 08:01:04 -0700, "sck10" <sc***@online.nospam>
wrote:
Hello,

I am looping through each control using the following to find a particular
control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product").

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"
For Each ctlMaster As Control In Page.Controls ' Page
If TypeOf ctlMaster Is MasterPage Then '
MasterPage
For Each ctlForm As Control In ctlMaster.Controls
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Controls
If TypeOf ctlContent Is ContentPlaceHolder Then
'ContentPlaceHolder
For Each ctlChild As Control In ctlContent.Controls

If TypeOf ctlChild Is TextBox Then
If ctlChild.ID = strFindCtl Then strSubmitter &=
CType(ctlChild, TextBox).Text & ", "
End If

Next
End If
Next
End If
Next
End If
Next
Next


Based on the article
(http://dotnetjunkies.com/WebLog/jpal...01/23919.aspx), I
am trying to follow the format for the following in order to reduce my code:
(MyUserControl)Page.Controls[0].FindControl(ā€¯ucMyUserControlā€¯);

However, when I use the following:

Dim ctlSteven As Control =
Page.Controls(0).FindControl("tbxCompetitor01Prod uct")
Response.Write(ctlSteven.ID)

I get the error:
I get the error: System.NullReferenceException: Object reference not set to
an instance of an object.

Any help with this would be appreciated.


Nov 18 '05 #3

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

Similar topics

1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
8
by: Workgroups | last post by:
I've got a page where the nature of the beast is such that the user clicks a submit button to ransomize some data in somewhat rapid succession (once per second, give or take). The page generates a...
6
by: Biguana | last post by:
Hi, Just wondering if anyone can help here. We have a site where most of the site opens in a window with no toolbars or menubar: window.open('mypage.aspx','self','toolbar=0, menubar=0, etc,...
0
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as ...
2
by: James | last post by:
I've been to websites where if I navigate off a form, trying to get back to it by hitting the back button gives me a page which says "Warning, page has expired". It doesn't display the page. I've...
4
by: Iyigun Cevik | last post by:
In my website, all of my pages have similar construction, for example background color, header part, a menu, and a general table which all contents're sitting in. I want to use these in several...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
2
by: Alex Maghen | last post by:
I have a site where most of the pages will have a common "shell" or layout. There will be an outer table which will hold HTML elements but which will *also* hold UserControls (Global Nav, etc.)....
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.