views:

203

answers:

2

hey guys,

I've read through a few other threads on here, though none of them really explain how to resolve my issue.

I have a web application with the following page (code behind)

namespace Company.Web.UI.Content
{
  public partial class Home_LoggedOut : Company.Web.UI.CompanyPage
  {
    string _myType = this.GetType().FullName.Replace(".", "_");
  }
}

Now I'd have hoped to get something like:

Company_Web_UI_Content_Home_LoggedOut

but instead I'm getting:

ASP_home_loggedout_aspx

I'm clearly missing something about class structures and how they work, so I'd like to understand that, but is there any way for me to get the fully qualified namespace + class name in this scenario?

Ideally, I'd like to include this in the base type (Company.Web.UI.CompanyPage) so that I can do something with it, so anything that is suggested would have to work at that level too.

Hope I'm not completely missing the point here (well, I probably am, but hopefully there is a way around it!)

Cheers, Terry

Update: Answer came in as:

string _myType = this.GetType().BaseType.FullName.Replace(".", "_");

thanks guys :)

A: 

When you have a page with a code behind you actually have two classes. One is from the code behind which gets inherited by the class for the page. That's why you get that name. Try this and see if it works:

string _myType = this.GetType().BaseType.FullName.Replace(".", "_");
rslite
+1 but its a little more complex than that. Much of the control markup in the ASPX page ends up creating a partial class with which the Code-behind partial class is combined forming the complete base class. Often there is very little in the inheriting class for the page except where there may be some in-line code or runat="server" script elements (why you'd use them when code-behind is available I don't know).
AnthonyWJones
+1  A: 

ASP.NET engine generates a class based on your ASPX markup and this class is inherited from Company.Web.UI.Content.Home_LoggedOut. You can try:

this.GetType().BaseType.FullName.Replace(".", "_")

Honestly, I've never tried it, but theoretically it should work =)

Vitaliy Liptchinsky