Avinash Chandra Avinash Chandra - 1 month ago 7
ASP.NET (C#) Question

Getting a URL from web.config

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.

Answer

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');";