admin管理员组

文章数量:1325361

I am trying to store a URL in the configuration file, but it does not work when I retrieve the URL from the file

Below is my code

In web.config, I have

 <add key="URL" value="/NG/Viewer/ViewerSummary.aspx"/>

In my aspx.cs page, I have the following code

string url = ConfigurationManager.AppSettings["URL"];

string strScript = "window.open(url?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);

the window does not open if I write the above code, but window opens if I do this below code.

string strScript = "window.open('/NG/Viewer/ViewerSummary.aspx?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);

How can I open the window by putting the value in the config file?
Any help is appreciated.

Thanks.

I am trying to store a URL in the configuration file, but it does not work when I retrieve the URL from the file

Below is my code

In web.config, I have

 <add key="URL" value="/NG/Viewer/ViewerSummary.aspx"/>

In my aspx.cs page, I have the following code

string url = ConfigurationManager.AppSettings["URL"];

string strScript = "window.open(url?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);

the window does not open if I write the above code, but window opens if I do this below code.

string strScript = "window.open('/NG/Viewer/ViewerSummary.aspx?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);

How can I open the window by putting the value in the config file?
Any help is appreciated.

Thanks.

Share Improve this question edited Oct 28, 2016 at 14:40 A1rPun 16.9k8 gold badges59 silver badges92 bronze badges asked Dec 11, 2012 at 17:35 Avinash ChandraAvinash Chandra 1831 gold badge9 silver badges24 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

It could be that your code that you have pasted has a couple errors. The first error is you're missing the opening single quote in the call to window.open. The other error is you aren't actually using the url variable.

Try this:

string strScript = "window.open('" + url + "?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
string strScript = "window.open('" + url + "?QueryID=" + QueryId + "', '_blank','height=650, center:yes, width=800, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=yes, status=no');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);

See the article listed below for using URLEncode method.

http://msdn.microsoft./en-us/library/zttxte6w.aspx

本文标签: cGetting a URL from webconfigStack Overflow