I'm using routing and change my urls. That works very good but I have a problem with my links.
When I look at a product details in this url http://mysite.com/Product/5226/electro-motors I want to click on a link which refers to the categories. Then url is http://mysite.com/Product/5226/electro-motors/Page/Contactus. This means "/Page/Contactus" is
added to my url which is invalid.
Links are not static and are made by menu manager in the site admin.
rrasheli
Member
18 Points
31 Posts
Problem with links in asp.net after routing
Nov 26, 2012 04:01 PM|LINK
Hi
I'm using routing and change my urls. That works very good but I have a problem with my links.
When I look at a product details in this url http://mysite.com/Product/5226/electro-motors I want to click on a link which refers to the categories. Then url is http://mysite.com/Product/5226/electro-motors/Page/Contactus. This means "/Page/Contactus" is added to my url which is invalid.
Links are not static and are made by menu manager in the site admin.
Please help me and say your solution.
Thanks.
yadiermolina
Member
366 Points
202 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 04:59 PM|LINK
add runat="server" to you link
rrasheli
Member
18 Points
31 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 05:03 PM|LINK
It does not work!
Why add runat="server" to links?
yadiermolina
Member
366 Points
202 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 05:07 PM|LINK
it shoud work.
can you send the link?
<a href="/dir/subdir" runat="server">example link</a>
rrasheli
Member
18 Points
31 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 05:14 PM|LINK
<a href="Contactus.aspx" runat="server">Contact us</a>
Of course this links are dynamicly generated.
string url = "Contactus.aspx"; string text = "Contact Us"; string menu = string.Format("<a href=\"{0}\" runat=\"server\">{1}</a>",url,text);yadiermolina
Member
366 Points
202 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 05:56 PM|LINK
so what error are you getting and which url are you directed to when clicking above link?
jprochazka
Contributor
4896 Points
740 Posts
Re: Problem with links in asp.net after routing
Nov 26, 2012 06:49 PM|LINK
Use Page.ResolveURL to correct the path issue.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx
string url = Page.ResolveUrl("Contactus.aspx"); string text = "Contact Us"; string menu = string.Format("<a href=\"{0}\" runat=\"server\">{1}</a>",url,text);