I am using a grid view inside a web user control. The gridview contains a hyperlinkfield.
I use this control in 3 separate directories within the application.
Directory structure
appRoot
Controls -> this folder contains web user control
folder1
UserView.aspx ->page uses control
Process.aspx
folder2
Default.aspx ->page uses control
Process.aspx
folder3
New.aspx -> page uses control
Process.aspx
How do I get relative url(s) for the hyperlink fields?
If I try to built
Case 1:DataNavigateUrlFormatString="~/Process.aspx?commandid={0}", it takes the approot for relative url, So the url is http://approot/Process.aspx?commandid=5GO53DS3BB.
Case 2:DataNavigateUrlFormatString="Process.aspx?commandid={0}", it takes control folder for relative url, So the url is http://approot/Controls/Process.aspx?commandid=5GO53DS3BB
In any case, the url I require is
http://approot/folder1/Process.aspx?commandid=5GO53DS3BB, or http://approot/folder2/Process.aspx?commandid=5GO53DS3BB or http://approot/folder3/Process.aspx?commandid=5GO53DS3BB when invoked from the respective folder.
You can use Request.Path, which returns the virtual path of the currently executing aspx (including page name). But you have to use them from code-behind as in: GridView1.DataNavigateUrlFormatString = Request.Path + "?commandID={0}";
Mark replies as answers if they helped you solve the problem.
I have a web user control (let us call it ProcessControl.ascx). ProcessControl.ascx contains a gridview. The grid view has a databound hyperlink field which call Process.aspx.
The ProcessControl.ascx is used in 3 aspx pages(UserView.aspx,Default.aspx,New.aspx) within different folder.
Let us go to the directory stucture
appRoot
Controls -> this folder contains web user control
ProcessControl.ascx
folder1
UserView.aspx ->page uses control
Process.aspx
folder2
Default.aspx ->page uses control
Process.aspx
folder3
New.aspx -> page uses control
Process.aspx
When I use ProcessControl.ascx in UserView.aspx in "folder1", the hyperlink field should point to Process.aspx inside folder1.
When I use ProcessControl.ascx in Default.aspx in "folder2", the hyperlink field should point to Process.aspx inside folder2.
When I use ProcessControl.ascx in New.aspx in "folder3", the hyperlink field should point to Process.aspx inside folder3.
In a single sentence the the hyperlink should take relative url of the aspx page which uses the control.
I had a feeling that is what you meant but wasn't sure
For something like this I would use Server.MapPath
For example a link to your page you could = Server.MapPath("/folder1/Process.aspx") that will take you from the root, to "folder1" to that web page inside folder1
I am aware of server.mappath, but this grid view is in a control, which is reused across pages as I mentioned in my post. So I cant hard code folder names.
azhar2000s
Member
10 Points
81 Posts
relative url in hyperlinkfield
Jun 26, 2008 01:02 PM|LINK
Hi
I am using a grid view inside a web user control. The gridview contains a hyperlinkfield.
I use this control in 3 separate directories within the application.
Directory structure
appRoot
Controls -> this folder contains web user control
folder1
UserView.aspx ->page uses control
Process.aspx
folder2
Default.aspx ->page uses control
Process.aspx
folder3
New.aspx -> page uses control
Process.aspx
How do I get relative url(s) for the hyperlink fields?
If I try to built
Case 1:DataNavigateUrlFormatString="~/Process.aspx?commandid={0}", it takes the approot for relative url, So the url is http://approot/Process.aspx?commandid=5GO53DS3BB.
Case 2:DataNavigateUrlFormatString="Process.aspx?commandid={0}", it takes control folder for relative url, So the url is http://approot/Controls/Process.aspx?commandid=5GO53DS3BB
In any case, the url I require is
http://approot/folder1/Process.aspx?commandid=5GO53DS3BB, or http://approot/folder2/Process.aspx?commandid=5GO53DS3BB or http://approot/folder3/Process.aspx?commandid=5GO53DS3BB when invoked from the respective folder.
drocco
Member
596 Points
566 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:20 PM|LINK
Could you state your issue another way? I don't understand your problem
siva_sm
Star
9409 Points
1375 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:30 PM|LINK
Prashant Kum...
Star
12346 Points
1993 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:33 PM|LINK
Try using ResolveUrl
http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx
azhar2000s
Member
10 Points
81 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:41 PM|LINK
Ok drocco, I will explain again.
I have a web user control (let us call it ProcessControl.ascx). ProcessControl.ascx contains a gridview. The grid view has a databound hyperlink field which call Process.aspx.
The ProcessControl.ascx is used in 3 aspx pages(UserView.aspx,Default.aspx,New.aspx) within different folder.
Let us go to the directory stucture
appRoot
Controls -> this folder contains web user control
ProcessControl.ascx
folder1
UserView.aspx ->page uses control
Process.aspx
folder2
Default.aspx ->page uses control
Process.aspx
folder3
New.aspx -> page uses control
Process.aspx
When I use ProcessControl.ascx in UserView.aspx in "folder1", the hyperlink field should point to Process.aspx inside folder1.
When I use ProcessControl.ascx in Default.aspx in "folder2", the hyperlink field should point to Process.aspx inside folder2.
When I use ProcessControl.ascx in New.aspx in "folder3", the hyperlink field should point to Process.aspx inside folder3.
In a single sentence the the hyperlink should take relative url of the aspx page which uses the control.
Hope I am clear.
drocco
Member
596 Points
566 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:50 PM|LINK
I had a feeling that is what you meant but wasn't sure
For something like this I would use Server.MapPath
For example a link to your page you could = Server.MapPath("/folder1/Process.aspx") that will take you from the root, to "folder1" to that web page inside folder1
Do the same for the others
azhar2000s
Member
10 Points
81 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 01:57 PM|LINK
I am aware of server.mappath, but this grid view is in a control, which is reused across pages as I mentioned in my post. So I cant hard code folder names.
azhar2000s
Member
10 Points
81 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 02:00 PM|LINK
Prashant Kumar
ResolveUrl looks like it can get the work done. I havnt checked is out in my code yet.
But I am looking for something which can be used declaratively. As these urls are in grid view. If not I have to change for each row data.
azhar2000s
Member
10 Points
81 Posts
Re: relative url in hyperlinkfield
Jun 26, 2008 02:37 PM|LINK
Anyway I can use ResolveUrl with asp:Hyperlinkflied tag?
I tried this:
<asp:HyperLinkField DataNavigateUrlFields="Id" NavigateUrl="<%ResolveClientUrl("~/Process.aspx")%>" HeaderText="Process" DataNavigateUrlFormatString="?commandid={0}" DataTextField="CmdName" />
But gives error
azhar2000s
Member
10 Points
81 Posts
Re: relative url in hyperlinkfield
Jun 28, 2008 05:45 AM|LINK
Still havnt got this working.
Anyone has any ideas???