Problem when using anchor in user control

R

remy.bur

Hi,
When adding an anchor (which is runat="server") in a user control, the
link generated will be based on the user control location and not on
the page which is using the control location.
For example, if the user control is located in an include folder, here
is what I will get:
<a href="include/home.aspx">
instead of
<a href="home.aspx">

I can't use "~/home.aspx" as a value for the href property because the
result I want is <a href="home.aspx"> and not
<a href="/home.aspx">

Any suggestion ?

Thanks in advance
 
K

Konstantinos Pantos

You could use a server hyperlink control instead of an Html anchor
<asp:Hyperlink ID="myHyperlink" runat="server" NavigateUrl="~/home.aspx"></asp:Hyperlink>
HTH

Kostas Pantos
 
R

remy.bur

You could use a server hyperlink control instead of an Html anchor
<asp:Hyperlink ID="myHyperlink" runat="server" NavigateUrl="~/home.aspx"></asp:Hyperlink>
HTH

Kostas Pantos





- Afficher le texte des messages précédents -

I've got the same problem with an hyperlink control. The result I want
is <a href="home.aspx"> and not
<a href="/home.aspx"> (no dash before "home.aspx")
 
K

Konstantinos Pantos

Are you going to change the location of home.aspx at runtime?
If not, then all you have to do is specify at your control the exact path
to your home.aspx.
<asp:Hyperlink ID="myHyperlink" runat="server" NavigateUrl="~/ExactPath/home.aspx"></asp:Hyperlink>
Your user control will always link to the right place because at runtime
it will replace ~ with "http://host/application".
HTH

Kostas Pantos
 

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
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top