Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 688101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:11:43+00:00 2026-05-14T02:11:43+00:00

I have my UserControls in a ~/Controls folder in my solution: /Controls/TheControl.ascx If specify

  • 0

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

/Controls/TheControl.ascx

If specify the following:

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

ASP.Net seems to want to rewrite the path to point to the absolute location. For example, If the control is on site.com/products/fish/cans.aspx the link href will be rewritten to read

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

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

I just want the anchor control to spit out exactly what I tell it to!!! Is that so hard?

EDIT:

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

Aspx page:

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

Code-behind:

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);

As you can see by the amount of code needed for what is essentially supposed to be be a simple and light-weight anchor, it’s not the most optimal solution. I know I could use a Literal but I figured this was cleaner as I’m adding more than one anchor.

I would be interesting in knowing WHY ASP.Net takes over and tries to fix my URL, though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:11:43+00:00Added an answer on May 14, 2026 at 2:11 am

    Why do you have runat="server" and no ID defined? Do you need to access it server side? If you remove the runat="server" everything will work as expected.

    For more information regardinging how ASP.NET handles paths check out this MSDN article.

    Edit: You can get around the problem then by using a Literal control and then outputing the raw <a href... to it.

    Eg:

    <asp:Literal ID="myLiteral" runat="server" />
    
    myLiteral.Text = "<a href=\"./?pg=1\">link text</a>";
    

    Then you can set the visible property on the Literal however you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several user controls, let's say A , B , C and D
I have some user controls that I'm loading in SharePoint and I would prefer
I have a UserControl with some predefined controls (groupbox,button,datagridview) on it, these controls are
I have a web user control that contains several other (web user) controls and
I have a .NET UserControl (FFX 3.5). This control contains several child Controls -
I have a canvas with user controls arranged on it. When a tooltip is
We have an application containing a lot of user controls that update frequently based
I have a bit of a problem with user controls. Basically what I want
When creating scrollable user controls with .NET and WinForms I have repeatedly encountered situations
Hi I have a view with several User Controls and I pass ViewData to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.