Code Access to Web Page Control properties

H

Hugh O

Hi,
I have been able to use the following kinds of code to access basic
information on the individual controls that would be in any Web page.

?Me.Controls(1).Controls(56).GetType.Name ' control type
?Me.Controls(1).Controls(56).ID ' control name

Is there a similar way of getting code access to the properties associated
with that control? I am talking about the properties that would appear in
the Property window within the Visual Basic.Net Designer phase.

Thanks,
hugh
 
D

Derek Harmon

Hugh O said:
Is there a similar way of getting code access to the properties associated with that control?

Sounds like what you're looking for is in the System.Reflection
namespace.

Essentially, you would:

1. Add Imports System.Reflection.
2. Get the Type of Me.Controls(1).Controls(56).
3. Enumerate it's properties (using the GetProperties( ) method) on
Me.Controls(1).Controls(56).GetType. This gives you a
collection of what are called PropertyInfo objects.
4. Pass Me.Controls( 1).Controls( 56) and some Value you
wish to assign to the PropertyInfo's SetValue( ) method.

Each PropertyInfo you get in step 3 will have a Name property, so
you can figure out if you're about to call SetValue( ) on the control's
Visible property or it's EnableViewstate property, for instance.


Derek Harmon
 
S

Steven Cheng[MSFT]

Thanks for Derek's informative inputs.

Hi Hugh,

As for accessing class instance's certian members (Property , field or
method, attributes...) without explictily cast them to their actual Class
reference, currently the System.Reflection namespace 's classes can help us
dynamically inspect instance's typeinfo (including class definiation,
members ....). You can try them through Hugh's suggetions.

#Metadata and Reflection in .NET
http://odetocode.com/Articles/288.aspx

Also, as for such dynamic Reflection, undoubtly they'll bring significant
performance overhead. So generally we'd recommend that you avoid using them
if possible.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| From: "Derek Harmon" <[email protected]>
| References: <[email protected]>
| Subject: Re: Code Access to Web Page Control properties
| Date: Thu, 22 Sep 2005 20:19:35 -0400
| Lines: 24
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: mailgw.infragistics.com 216.113.236.146
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.languages.vb:107062
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| > Is there a similar way of getting code access to the properties
associated with that control?
|
| Sounds like what you're looking for is in the System.Reflection
| namespace.
|
| Essentially, you would:
|
| 1. Add Imports System.Reflection.
| 2. Get the Type of Me.Controls(1).Controls(56).
| 3. Enumerate it's properties (using the GetProperties( ) method) on
| Me.Controls(1).Controls(56).GetType. This gives you a
| collection of what are called PropertyInfo objects.
| 4. Pass Me.Controls( 1).Controls( 56) and some Value you
| wish to assign to the PropertyInfo's SetValue( ) method.
|
| Each PropertyInfo you get in step 3 will have a Name property, so
| you can figure out if you're about to call SetValue( ) on the control's
| Visible property or it's EnableViewstate property, for instance.
|
|
| Derek Harmon
|
|
|
 
H

Hugh O

Thanks Derek and Steven,
It was just a proposed tool to use in development, merely for generating
summary control documentation I was not planning on using it for setting
properties in runtime.


thanks,
hugh
 
S

Steven Cheng[MSFT]

Thanks for your followup Huge,

If just for development usage, then feel free to use it :)

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Hugh O" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Code Access to Web Page Control properties
| Date: Fri, 23 Sep 2005 09:49:46 -0400
| Lines: 37
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: pcp01784214pcs.audubn01.nj.comcast.net 68.46.176.167
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp1
3.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.languages.vb:107158
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thanks Derek and Steven,
| It was just a proposed tool to use in development, merely for generating
| summary control documentation I was not planning on using it for setting
| properties in runtime.
|
|
| thanks,
| hugh
| | > | >> Is there a similar way of getting code access to the properties
| >> associated with that control?
| >
| > Sounds like what you're looking for is in the System.Reflection
| > namespace.
| >
| > Essentially, you would:
| >
| > 1. Add Imports System.Reflection.
| > 2. Get the Type of Me.Controls(1).Controls(56).
| > 3. Enumerate it's properties (using the GetProperties( ) method) on
| > Me.Controls(1).Controls(56).GetType. This gives you a
| > collection of what are called PropertyInfo objects.
| > 4. Pass Me.Controls( 1).Controls( 56) and some Value you
| > wish to assign to the PropertyInfo's SetValue( ) method.
| >
| > Each PropertyInfo you get in step 3 will have a Name property, so
| > you can figure out if you're about to call SetValue( ) on the control's
| > Visible property or it's EnableViewstate property, for instance.
| >
| >
| > Derek Harmon
| >
|
|
|
 

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

Top