Problem when using anchor in user control

  • Thread starter Thread starter remy.bur
  • Start date Start date
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
 
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
 
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")
 
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
 
Back
Top