this.Page.Id empty

S

STech

What is the recommended method to get a unique property of the page that a
custom webcontrol is in.

this.Parent.Page.ID
this.Parent.Page.ClientID
this.Parent.Page.UniqueID

Will I have to end up using reflection?

Thanks.
 
S

Steven Cheng[MSFT]

Hi Stech,

Welcome to ASPNET newsgroup. As for the Page's ID, UniqueID , ClientID
property, they're also the properteis of the Control class. The ClientID
property is used for webcontrol's clientside DOM element's identity. The
UniqueID is used for those html input elements whose value will be posted
back to server in the REquest's Form collection , and the UniqueID is
rendered as "name" html attribute at clientside. The ID , however, is the
unique identifier of the ASP.NET controls at serverside.

As for a Page, when constructed at serverside , the asp.net runtime will
not set an ID for it, also, there is not need for it to has an UniqueID or
ClientID. Why do you want to get the Page's ID? would you provide some
further info on your problems so that we can try looking for some means
else?

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.)
 
S

STech

Steven,

Thanks for the reply.
Why do you want to get the Page's ID?

I need to add an item to the session from within the custom webcontrol. The
item obviously has to be unique per custom webcontrol per page. I was hoping
to use this.UniqueId + this.Page.UniqueId + "stringidentifier".

Thanks.
 
S

Steven Cheng[MSFT]

Thanks for your followup Stech,

If you need to identify controls on a certain page, I'm afraid the Page's
ID(or clientID, UniqueID) is not reliable since when Control is constructed
(with defaut contructor), no ID will be assigned , only when they're added
into a NamingContainer or other parent controls will they be assigned an
random ID.

AS for your scenario, I think we have the following options:

Generate a custom unique ID ourself ,maybe through the page class name and
the current date. Then store the ID into the page's or control's ViewState
so that we can retrieve it back again the next time.

If you have any other questions, please feel free to post here also. 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.)
 

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
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top