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

  • SEARCH
  • Home
  • 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 736931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:39:42+00:00 2026-05-14T07:39:42+00:00

I have a user control that contains a GridView. The GridView has both a

  • 0

I have a user control that contains a GridView. The GridView has both a HyperLinkField column and a template column that contains a HyperLink control.

The ASP.NET project is structured as follows, with the Default.aspx page in each case using the user control.

  • Application Root
    • Controls
      • UserControl with GridView
    • SystemAdminFolder
      • Default.aspx
      • Edit.aspx
    • OrganisationAdminFolder
      • Default.aspx
      • Edit.aspx
    • StandardUserFolder
      • Default.aspx
      • Edit.aspx

Note: The folders are being used to ensure the user has the correct role.

I need to be able to set the DataNavigateUrlFormatString for the HyperLinkField and the NavigateUrl for the HyperLink to resolve to the Edit.aspx page in the corresponding folder.

If I set the navigate URL to “Edit.aspx” the URL in the browser appears as
‘http://Application Root/Controls/Edit.aspx’ regardless of the originating directory.

I can’t use the Web application root operator (~/) as the path needs to be relative to the current page, not the application root.

How can I use the same user control in multiple folders and resolve the URL to another page in the same folder?

Note: The question is strongly based off a similar question by azhar2000s on the asp.net forums that matches my problem.

  • 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-14T07:39:42+00:00Added an answer on May 14, 2026 at 7:39 am

    While typing up this question I came across one possible solution and have further modified this using feedback from @Thomas.

    Changing Control.AppRelativeTemplateSourceDirectory alters the relative paths produced by the control. I’ve set it to a root relative virtual path for the current requests folder. Now any relative paths in the UserControl with be relative to the requested page rather than the user controls path.

    //Page Load Event for the User Control
    protected void Page_Load(object sender, EventArgs e)
    {
        string rootPath = HttpContext.Current.Request.ApplicationPath;
        if (!rootPath.EndsWith("/"))
        {
            rootPath += "/";
        }
    
        Uri requestUri = HttpContext.Current.Request.Url;
        string folderPath = requestUri.AbsolutePath.Remove(0, rootPath.Length);
        string lastSegment = requestUri.Segments[requestUri.Segments.Length - 1];
        folderPath = folderPath.Remove(folderPath.LastIndexOf(lastSegment));
    
        AppRelativeTemplateSourceDirectory = "~/" + folderPath;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want to call setlocale() first, "LC_ALL" should do… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Linux Ubuntu Desktop Jaunty Firebug FireCookie Pixel Perfect Web developer… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Your code should look like this: var par = [];… May 14, 2026 at 9:06 am

Related Questions

This question seems to have been asked before, but I feel like my situation
I have a ASP.NET GridView that uses template columns and user controls to allow
I have user control on a ASP.NET web page, which contains a GridView and
I have a web page with a GridView. The GridView contains a list of
I have a simple GridView ; something like this for a regular Item or

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.