PS: RootUrl is bit critical here: I have tested RootUrl property. However you can use it if you want, but if you get problems please have a web.config configrued value for root url. We never know where it go wrong. It might work on local but when you deploy it to live or a in some extrem conditions it might stop working.
Here is an example:
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Test Page</title> <script runat="server"> public string RootUrl { get { Uri requestUri = Context.Request.Url; HttpRequest request = Context.Request; string rootUrl = string.Format("{0}{1}{2}{3}{4}", requestUri.Scheme, Uri.SchemeDelimiter, requestUri.Host, requestUri.IsDefaultPort ? string.Empty : string.Format(":{0}", requestUri.Port), request.ApplicationPath); return rootUrl.EndsWith("/") ? rootUrl : string.Format("{0}/", rootUrl); } } private string script = @" window.open('{0}','', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); "; protected void OpenWindow(object sender, EventArgs e) { string page = string.Concat( this.RootUrl, ((LinkButton)sender).CommandArgument); /// /// Check your condition /// bool myCondition = true; if (myCondition) { Page.ClientScript.RegisterClientScriptBlock( this.GetType(), this.GetType().Name, string.Format(this.script, page), true); } } </script> </head> <body> <form id="form1" runat="server"> <asp:LinkButton runat="server" ID="lnkButton" OnClick="OpenWindow" Text="Open a Window" CommandArgument="Tutorials/Rocky/Training.pdf" /> </form> </body> </html>
No comments:
Post a Comment