Why are backward slashes removed from querystring - ASP.NET & Javascript
<p>I am trying to generate a URL that contains a UNC path as one of the query string variables.  The URL will open in a pop up window when an ASP.NET button control is clicked by the user.  When the clicks the button, the backwards slashes are removed from the UNC path causing the page to break.</p>

<p>The button renders correctly in the page source file with all the backward slashes.</p>

<p>Is there any way to prevent this?</p>

<p>Here is my source code:</p>

<p>Code behind:</p>

<pre><code>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 + @"')");
</code></pre>

<p>ASPX page</p>

<pre><code>&lt;script language="javascript" type="text\javascript"&gt;
    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();
    }
&lt;/script&gt;

&lt;asp:button id="MyButton" runat="server" cssclass="mycss" text="View Actual Target" /&gt;
</code></pre>

<p><b>Update</b></p>

<p>Server.UrlEncode does not work.  Same behavior.</p>

<p><b>Update 1</b></p>

<p>Based on Daniel Lew's answer, I developed the following solution:</p>

<pre><code>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(@"\", @"\\"); 
}
</code></pre>
