HTML Controls and User controls

T

trinitypete

I have a user control that is basically a login dialogue.
If I add the user control to webpage1, can I access the
properties directly from C# codebehind, or do I have to
access the properties from HTML behind webpage1.

Thanks in advance. Pete
 
T

trinitypete

Webpage1 is a standard ASP.NET webform which contains the
user control. I know I can access properties of the user
control via the HTML of webpage1 i.e.
<uc1:LoginUserControl id="LoginUserControl1"
property1="Hello" property2="Goodbye"
runat="server"></uc1:LoginUserControl>

but is it possible to access the properties from webpage1
code behind page.

Hope this is a little clearer.
Pete.
 
R

Ryan Fiorini

Yes It is possible. Here is the code to do it.

Dim _myControl As Control = Page.FindControl("UserControlName")
Dim _myControlType As Type = _myControl.GetType()
Dim _myControl_Property As PropertyInfo =
_myControlType.GetProperty("PROPERTYNAME")

sTemp = _myControl_Property.GetValue(_myControl, Nothing)


Hope this helps.

Ryan
 
T

trinitypete

It worked a treat - Thanks.
-----Original Message-----
Yes It is possible. Here is the code to do it.

Dim _myControl As Control = Page.FindControl ("UserControlName")
Dim _myControlType As Type = _myControl.GetType()
Dim _myControl_Property As PropertyInfo =
_myControlType.GetProperty("PROPERTYNAME")

sTemp = _myControl_Property.GetValue (_myControl, Nothing)


Hope this helps.

Ryan





.
 
K

Kevin Spencer

Your CodeBehind Page should have a reference to the control if you used the
tag you mentioned in your reply. You can therefore access the properties of
the object in your CodeBehind (using its' ID) without any problem.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.
 
K

Kevin Spencer

T

trinitypete

Thanks Kevin,

Will research link.
-----Original Message-----
Sorry trinitypete,

I misunderstood your question, and neglected to observe that you were
talking about a User Control instead of a Server Control. Handling the User
Control from your CodeBehind is a bit trickier than a Server Control. The
following MSDN article should help:

http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpguide/html/cpconexposingpageletproperties.asp

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top