Why does ASP.Net rewrite relative paths for runat = server anchor controls?

I have my UserControls in the ~ / Controls folder in my solution:

/Controls/TheControl.ascx

If the following is indicated:

<a id="theId" runat="server" href="./?pg=1">link text</a>

It seems that ASP.Net wants to rewrite the path to an absolute location. For example, if the control is on site.com/products/fish/cans.aspx, the href link will be overwritten for reading

<a id="munged_theId" href="../../Controls/?pg=1>link text</a>

Why is Asp.Net rewriting these control paths and is there an elegant way to fix it?

I just want the anchor control to spit out exactly what I'm telling him !!! Is it that hard?

EDIT:

I basically did what Kelsey suggested. I knew I could do it this way, but I don't like adding markup to my code when I want something relatively simple. At least this solves the problem:

Aspx Page:

<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>

Code for:

var anchor = new HtmlGenericControl("a") { InnerText = "Previous" + " " + PageSize) };
anchor.Attributes["href"] = "?pg=" + (CurrentPage - 1);
anchor.Attributes["class"] = "prev button";
ph.Controls.Clear();
ph.Controls.Add(anchor);

, , , . , Literal, , , .

, ASP.Net URL.

+5
5

runat="server" no ID? ? runat="server", , .

, ASP.NET , MSDN.

:. , Literal, <a href....

:

<asp:Literal ID="myLiteral" runat="server" />

myLiteral.Text = "<a href=\"./?pg=1\">link text</a>";

Literal, .

+4

, , , , , , ascx:

<anchor id="myAnchor" runat="server" href="xxx">link text</anchor>

HtmlGenericControl :

myAnchor.TagName = "a";
// other properties set as needed

, , , - .

+4

, ~/ URL. .

+1

. ASP.NET UserControl .

, HRef Request.Path. URL- .

, , Kelsey, ~/, Wyatt.

+1

, ICallBackEventHandler RenderControl ... :/, JQuery:

$('#munged_theId').attr('href', './?pg=1');
0

All Articles