Relative path from an ASP.NET user control NavigateUrl
- by Daniel Ballinger
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.