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

accessing controls in web forms user control

Is there a way to access controls (and their properties) in a user control?
The Web Form Designer marks controls as 'Protected' which makes them
inaccessable from the host form. If I mark them as Public, I can access
them, but the next time the controls are manipulated in the design mode,
they are converted back to Protected. Is there an obvious/easy way around
this?

Thanks.
Nov 19 '05 #1
6 2236
Do you want to use the controls "from outside"?
Why do you need that?

I think there may be better ways to achieve what you want to do.

If you can explain you base problem, it may be better.
--
Cheers,
Gaurav Vaish
http://mastergaurav.blogspot.com
http://mastergaurav.org
-------------------

Nov 19 '05 #2
Lee

Hi ;)

How about exposing the controls you're interested in as public properties?

e.g.

protected System.Web.UI.WebControls.TextBox m_editName;

public TextBox Name {
get { return m_editName; }
}

"arvee" <no****@spam.not> wrote in news:otale.221$zb.210@trndny04:
Is there a way to access controls (and their properties) in a user
control? The Web Form Designer marks controls as 'Protected' which
makes them inaccessable from the host form. If I mark them as Public,
I can access them, but the next time the controls are manipulated in
the design mode, they are converted back to Protected. Is there an
obvious/easy way around this?

Thanks.


Nov 19 '05 #3
Hi Lee,

This is where arvee is having trouble.

The VS.Net designer re-marks them as "protected" everything it is
accessed in DesignMode.

But arvee,

I think it can be made public in the "properties" pane. Right click
the control, select properties and make it "public" through that entry.
You should be able to do it.
--
Cheers,
Gaurav Vaish
http://mastergaurav.blogspot.com
http://mastergaurav.org
------------------

Nov 19 '05 #4
MasterGaurav,

My user control contains several web form server controls such as label
controls. My hope was to add the user control to a web form and
programatically set the .Text property of the labels. For example:

Dim newUserControl as myUserControl = LoadControl("blah.apcx")
newUserControl.lblTitle.Text = "Hello World!"

As the Web Form Designer sets the child controls on the user control as
Protected, the code on the Parent web form is restricted from accessing
them. I suppose its a good object design, but in my case, I'd like to
get easy access to them (yeah, I'm lazy).

I worked around it for now by adding my own Public properties that are
exposed from the parent form. In the Page_Load event of the user
control, I assign the public properties (string type) to the .Text
properties of the label controls.

Seemed like there may be an easier way, but hey, that's why we get paid
the big bucks (ha ha).

Nov 19 '05 #5
Lee

I understood that he was trying to change the declaration of the control.

e.g. trying to change
protected TextBox Name
to
public TextBox Name

What I'm proposing is adding a public property which simply delegates to
the control declaration.

I tested this prior to posting, hoping to verify that the designer won't
remark the property (it doesn't) - I also noted that it doesn't remark
the control declaration either (certainly not when changing protected to
public in the code editor - I also tried switching back and forth between
the form view, html view and code view), so I dunno what problem arvee is
having.

"MasterGaurav" <ga**********@gmail.com> wrote in
news:11**********************@g43g2000cwa.googlegr oups.com:
Hi Lee,

This is where arvee is having trouble.

The VS.Net designer re-marks them as "protected" everything it is
accessed in DesignMode.

But arvee,

I think it can be made public in the "properties" pane. Right click
the control, select properties and make it "public" through that entry.
You should be able to do it.
--
Cheers,
Gaurav Vaish
http://mastergaurav.blogspot.com
http://mastergaurav.org
------------------


Nov 19 '05 #6
Arvee:

I would recommend not providing direct acess to any field. Use
properties. I know you are using your code internally (for consumption
within your code) but still, why make it attack-prone by exposing the
field as public?

--
Cheers,
Gaurav Vaish
http://mastergaurav.blogspot.com
http://mastergaurav.org
---------------------

Nov 19 '05 #7

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
2
by: Ken Varn | last post by:
Not sure if this newsgroup is the right forum for this post. I have been experimenting with embedding .NET Windows Forms User Controls into a web page. I have been pleased with the results that...
3
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount...
7
by: Sudhakara.T.P. | last post by:
Hi, I have an tab control in one of the forms and it has two tab strips. Now I have written an general function that accepts form name as parameter and iterates through all the controls in the...
3
by: tshad | last post by:
I am trying to put together a user control (.ascx). Can you access an outside control from it? My control: login2.ascx ****************************************************************...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
8
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
0
by: morathm | last post by:
I have a windows client database management application written in C# that connects to remote web services to do all the heavy work. The thin-client app uses strong typed datasets, all maintained at...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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...
0
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...

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.