How to let my web-user-control determine automatically the url of the page where it's placed
<asp:HyperLink
ID="hyper1"
runat="server"
NavigateUrl='<%#string.Format("~/PLayer.aspx?ID={0}&Type={1}",Eval("arrange_by_id"),Eval("value"))%>'><%# Eval("value")%></asp:HyperLink>
I've implemented this string format in my NavigateUrl to pass a dynamic querystring depending on the clicked item!
but you see the first part in the string format whe开发者_JAVA技巧re it says "~/PLayer.aspx" i want the user control to automatically change this part according to where it's placed!
try this http://www.codeproject.com/KB/aspnet/resolveurl.aspx
how about this:
NavigateUrl='<%#string.Format("{2}?ID={0}&Type={1}",
Eval("arrange_by_id"),Eval("value"), Page.ResolveUrl("~/Palyer.aspx"))%>'
You could try Request.ServerVariables["SCRIPT_NAME"], it will return the name of the current page.
You don't need to move the user control from place to place. You can only get the name of the current page from either Request.Url
, Request.RawUrl
or Request.ServerVariables["SCRIPT_NAME"]
.
You can dynamically register user control to change the path when you want it like that. For a reference on dynamically registering user control see this
精彩评论