bevacqua
bevacqua

Reputation: 48476

C# Get page type name?

I'm trying to get a Page's type, to assign it to a div's id.

I tried:

<div id="<%= this.Page.GetType().Name %>" class="website-content">

But I got it in the form

master_page_name_aspx

I also tried

<div id="<%= this.Page.GetType().GetType().Name %>" class="website-content">

but it produced RuntimeType

I'd like to get, for example, EditUser, or whatever the page web form class is called.

How can I achieve this?

Upvotes: 1

Views: 3459

Answers (2)

QuinnG
QuinnG

Reputation: 6424

Doing <%= GetType().BaseType.Name %> on a default WebApp in VS2010 gave me the class for the page.

Upvotes: 1

Asbj&#248;rn Ulsberg
Asbj&#248;rn Ulsberg

Reputation: 8820

What you want is probably:

<div id="<%= this.Page.GetType().BaseType.Name %>" class="website-content">

Since GetType().GetType() will only return the same type, regardless of how many times you invoke it.

Upvotes: 3

Related Questions