views:

94

answers:

2

Hello everyone, I know that in markup view Visual Studio will provide you with an enumeration of all the page names in your project (add an element and see what you get from Intellisense when specifying the ImageUrl attribute).

My question is: how do I get to that enumeration?

If that's not possible, what would be the best way in asp.net to get the names of your pages without having to hard code strings all over the place? E.g., I'd like to be able to do something like this:

Response.Redirect(PageNames.Default);

(Where PageNames is an enum of some sort)

Is this possible? Thanks in advance!

+1  A: 

Here is one suggestion...

Define a class that includes the pages you want, either manually or by reading a Site Navigation file:

static class PageNames
{
    public static string Default = "~/Default.aspx";
    public static string Contact = "~/Contact.aspx";
    public static string About = "~/About.aspx";
}

You can use the class by calling the property name:

Response.Redirect(PageNames.Default);
Dscoduc
A: 

Another option, that I have looked at but not tried out yet (might next week tho'):
http://blog.devarchive.net/2008/01/auto-generate-strong-typed-navigation.html

Looks very cool, uses T4 templating to generate a strongly typed navigation hierarchy.

seanb
Thanks for your reply; I definitely think this is a clever solution. Sorry for the delay... I asked the question as a guest user and I couldn't accept your answer until now.
Paul