473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page.Controls(0 ).FindControl(" tbxCompetitor01 Product")

Hello,

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

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompeti tor" & 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.Contr ols
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Control s
If TypeOf ctlContent Is ContentPlaceHol der Then
'ContentPlaceHo lder
For Each ctlChild As Control In ctlContent.Cont rols

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(ā€ ¯ucMyUserContro lā€¯);

However, when I use the following:

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

I get the error:
I get the error: System.NullRefe renceException: 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 3905
Hi sck10:

You have to be aware of 'naming containers' when using FindControl.
You'll need to invoke FindControl on the ContentPlaceHol der 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.n ospam>
wrote:
Hello,

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

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompeti tor" & 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.Contr ols
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Control s
If TypeOf ctlContent Is ContentPlaceHol der Then
'ContentPlaceH older
For Each ctlChild As Control In ctlContent.Cont rols

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(”u cMyUserControl” );

However, when I use the following:

Dim ctlSteven As Control =
Page.Controls( 0).FindControl( "tbxCompetitor0 1Product")
Response.Write (ctlSteven.ID)

I get the error:
I get the error: System.NullRefe renceException: 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 contentplacehol der 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:ContentPla ceHolder ID="cphMainCont ent"
Runat="server"> </asp:ContentPlac eHolder>

Is on the content page:
<asp:Content ID="Content1" ContentPlaceHol derID="cphMainC ontent"
Runat="server">

This works...
For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompeti tor" & strForLoop1 & "Product"
ctlFind = Master.FindCont rol("cphMainCon tent").FindCont rol(strFindCtl)
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 ContentPlaceHol der 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.n ospam>
wrote:
Hello,

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

For ctrRow = 1 To 3
strForLoop1 = "0" & ctrRow
strFindCtl = "tbxCompeti tor" & 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.Contr ols
If TypeOf ctlForm Is HtmlForm Then '
HtmlForm
For Each ctlContent As Control In ctlForm.Control s
If TypeOf ctlContent Is ContentPlaceHol der Then
'ContentPlaceH older
For Each ctlChild As Control In ctlContent.Cont rols

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(ā€ ¯ucMyUserContro lā€¯);

However, when I use the following:

Dim ctlSteven As Control =
Page.Controls( 0).FindControl( "tbxCompetitor0 1Product")
Response.Write (ctlSteven.ID)

I get the error:
I get the error: System.NullRefe renceException: 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
4192
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 in IE as well as FireFox. This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL 4.1.8 and it works fine. The problem server is a Win2k server, IIS5, PHP 5.0.4, mySQL 4.1.11.
8
3045
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 little table, 10x10, of small pictures that represent the randomized data. The submit button tells the server (which is keeping track of which pictures are where) to scramble them around and output a new table. The output is simple HTML. The...
6
19612
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, etc) This is because it's a data driven site where space is at a premium and we'd rather discourage use of back, stop and refresh. The problem arises because some "view data" pages are designed to be printed and have an onclick="window.print();"...
0
2430
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 <fo:layout-master-set> <fo:simple-page-master margin-left="0.5in" margin-right="0.5in" page-width="8.5in" margin-bottom="0.5in" master-name="Section-odd-page" margin-top="0.5in" page-height="14in"> <fo:region-after region-name="xsl-region-after-odd"
2
4336
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 been searching around trying to get this to happen for one of my aspx pages and I can't get it to expire. I've put the following HTML tags in the page: <meta http-equiv="expires" content="Sun, Dec 31 1970 12:00:00 GMT"> <meta...
4
1141
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 pages in my application. For menu and header i can make server controls. But for backgroud color of page and for a table covering all of the page i can't make it. The idea of making a template page and inheriting it in all pages appeared in my...
4
2801
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 one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created on the page. So I need multiple forms on a asp.net page(doesn't everyone). I purchased the...
8
2572
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 courses are populated. When course is selected, lists of occurrences, groups and
2
1756
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.). Right now, all of the HTML and the @ Register directives for the shell's UserControls are copied onto each and every .ASCX page on the site I find this kind of frustrating because it means that I have to change many files whenever I want to make...
2
3624
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
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.