I am trying to create a url containing a UNC path as one of the query string variables. The URL will open in a popup when the ASP.NET user control clicks on the user. When a button is clicked, backslashes are removed from the UNC path, resulting in a page break.
The button displays correctly in the original page file with all backslashes.
Is there any way to prevent this?
Here is my source code:
Code behind:
string unc = @"\\myserver\myfolder\myfile.txt";
string url = string.Format("http://www.mysite.com/page.aspx?a={0}", unc);
MyButton.Attributes.Add("onclick", @"javascript:FullPop('" + url + @"')");
Aspx page
<script language="javascript" type="text\javascript">
function FullPop(Newurl) {
Win = window.open( Newurl,"Monitor", "fullscreen=0,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600,top=50,left=50");
Win.focus();
}
</script>
<asp:button id="MyButton" runat="server" cssclass="mycss" text="View Actual Target" />
Update
Server.UrlEncode is not working. The same behavior.
Update 1
Based on Daniel Lew's answer, I developed the following solution:
protected void Page_Load(object sender, EventArgs e)
{
string unc = @"\\myserver\myfolder\myfile.txt";
string url = string.Format("http://www.mysite.com/page.aspx?a={0}", unc);
MyButton.Attributes.Add("onclick", @"javascript:FullPop('" + this.EscapeforJavaScript(url) + @"')");
}
private string EscapeforJavaScript(string url)
{
return url.Replace(@"\", @"\\");
}