473,624 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a control from another page

How do I access a control, like a placeholder, from another page, or another
user control that may be on the same page.

For instance, I have a web page with 2 user controls. One user controls
contains a placeholder to that will contain any error messages to be
displayed. If the first user control creates an error, I want to be able to
push that error to the 2nd control to display it at the placeholder.

I have tried
Dim ctrlError as new ucErrors
Dim lbl as new label
lbl.text = "Error has occurred"
ctrlError.ph.Co ntrols.Add(lbl)

But I get an error saying "System.NullRef erenceException : Object reference
not set to an instance of an object."



Nov 19 '05 #1
2 2047
I'm no expert in the subject, but I don't know of a way to get two user
controls to talk to each other directly.

One way to empower communication is indirectly through the parent page. For
example, you may have two user controls on a page, uc1 and uc2. If uc1 has
an error, have it create and event which will be received by the parent and
acted on by an event handler in the parent. The parent will have a direct
reference to uc2, so you can then set properties or do whatever you want
with uc2 in the event handler.

Also, your code snippet looks like you are trying to dynamically create an
instance of a user control. I've always done this using the loadcontrol
call, for example
Dim questionDisplay Ctrl As Control =
LoadControl("../templates/questionListIte mOptions.ascx")

What you are trying to do (Dim ctrlError as new ucErrors) looks more
suitable for a regular web server control, class, or a composite control.

"eagle" <ea***@yahoo.co m> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
How do I access a control, like a placeholder, from another page, or
another user control that may be on the same page.

For instance, I have a web page with 2 user controls. One user controls
contains a placeholder to that will contain any error messages to be
displayed. If the first user control creates an error, I want to be able
to push that error to the 2nd control to display it at the placeholder.

I have tried
Dim ctrlError as new ucErrors
Dim lbl as new label
lbl.text = "Error has occurred"
ctrlError.ph.Co ntrols.Add(lbl)

But I get an error saying "System.NullRef erenceException : Object reference
not set to an instance of an object."

Nov 19 '05 #2
Yes, that's right. You have to go through the parent page because the two
controls don't know anything about each other.

However, you shouldn't need to create a new instance of the control in your
code, because the parent page should automatically create it when it loads
up the .aspx file and sees the @Control directive, <uc:Control> tag, etc. So
the best way to access the control is to use the parent page's Page.Controls
property. Here's an example...this is terrible VB but you'll get the idea
;-)

' Assuming we are in the first user control

Dim ctrlErrorId
ctrlErrorId = "MyUserCont rol" ' need a variable for the user control ID,
otherwise how does it know which one to find?

Dim ctrlError as ucErrors
ctrlError = Parent.FindCont rol(ctrlErrorId )
' ctrlError now contains a reference to the error control

Hope that helps!

--

Joshua Mitts
jo****@msn.com

"HoustonFreeway s" <es*******@NOco mcastSPAM.com> wrote in message
news:Yo******** ************@co mcast.com...
I'm no expert in the subject, but I don't know of a way to get two user
controls to talk to each other directly.

One way to empower communication is indirectly through the parent page.
For example, you may have two user controls on a page, uc1 and uc2. If uc1
has an error, have it create and event which will be received by the
parent and acted on by an event handler in the parent. The parent will
have a direct reference to uc2, so you can then set properties or do
whatever you want with uc2 in the event handler.

Also, your code snippet looks like you are trying to dynamically create an
instance of a user control. I've always done this using the loadcontrol
call, for example
Dim questionDisplay Ctrl As Control =
LoadControl("../templates/questionListIte mOptions.ascx")

What you are trying to do (Dim ctrlError as new ucErrors) looks more
suitable for a regular web server control, class, or a composite control.

"eagle" <ea***@yahoo.co m> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...
How do I access a control, like a placeholder, from another page, or
another user control that may be on the same page.

For instance, I have a web page with 2 user controls. One user controls
contains a placeholder to that will contain any error messages to be
displayed. If the first user control creates an error, I want to be able
to push that error to the 2nd control to display it at the placeholder.

I have tried
Dim ctrlError as new ucErrors
Dim lbl as new label
lbl.text = "Error has occurred"
ctrlError.ph.Co ntrols.Add(lbl)

But I get an error saying "System.NullRef erenceException : Object
reference not set to an instance of an object."


Nov 19 '05 #3

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

Similar topics

3
15097
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture the field values and write them to an ASCII file on the hard drive. Can anyone confirm that this is even possible? I have dredged up one article "Accessing the Internet Explorer Document Object Model from Visual Basic 5.0" (Asmi, 1998) that covers...
4
2049
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's help) in a click event of the button that is pushed to enter data. Each time the button is clicked it sends the ID entered by the user to query the database and return information. The renamed controls then include the ID in the name of the...
2
1387
by: Willy | last post by:
Hi All! Is there any ways to get access to the controls contained in another user controls from an ASP.NET page? For example I have... - User Control A |_ User Control B (which uses User Control A) |_ User Control C (which uses User Control B)
1
1423
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have added a web user control to my project and placed some common controls over there.In order to access the control from another web page i registered with it(aspx page) using register tag accessed it.Now i want to set a value to it in the Page_Init() code of my web page.How do i access it from my vb page? Regards Reny
2
1475
by: RKT | last post by:
(Web Developer Express 2005, CSharp, C#) I've searched high and low... If have the typical _Default page. In it is a MultiView that contains another MultiView - in both of those are Views containing my specialized UserControls. In any of those views, I need to acess the _Default page (parent, several times removed). I would like a strongly typed mechanism, but at this point,
9
2642
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method to another location because it populates a Textbox in the user control page. Thanks Andrew
3
1566
by: Nathan Sokalski | last post by:
I have a validator that I wrote by inheriting from BaseValidator. At certain points in the code, I need to access other controls on the page containing the validator. I have the IDs of these controls, so I use the following statement to access them: Me.Page.FindControl(ControlID) However, this is returning Nothing, even though the control can be accessed in the Load event of the Page containing the control and the validator. I also...
8
10817
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList steps successfully with the following code... Control myContainer = (Control)Wizard1.FindControl("SideBarContainer"); DataList mySideBarList = (DataList)myContainer.FindControl("SideBarList");
2
3042
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main form Main Tab Control - This contains Main Tab Pages.
0
8240
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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
8625
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
8336
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,...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
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();...
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
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.