1
<appSettings>
<add key="pat_ins_suc" value="patient registration successful."/>
</appSettings>

i want to display the value using JavaScript alert() function in the browser using one method call.

public void display()
{
string msg = ConfigurationManager.AppSettings["pat_ins_suc"];
}

how to pass the string msg inside the alert() function so that it will display in the web browser.

  • You can get this value in C# code and can pass it value to javascriot function but in javascript you can't get value of Appsetting. – Kevin Shah Apr 09 '18 at 07:39
  • Possible duplicate of [AppSettings get value from .config file](https://stackoverflow.com/questions/10766654/appsettings-get-value-from-config-file) – VDWWD Apr 09 '18 at 08:10
  • this is not duplicate. my question is after retrieving the value how to display this value using alert function of javascript. i think you can understand – Bijnana Acharya Apr 09 '18 at 08:34

4 Answers4

0

try this. i hope this helps

<script type="text/javascript">
    var patinMessage= '<%=ConfigurationManager.AppSettings["pat_ins_suc"]%>';
</script>
user9405863
  • 1,506
  • 1
  • 11
  • 16
0
  1. In Page Load event store the config value in hidden fields using Config Manager.
  2. Retire from hidden fields using JQuery.
  3. JQuery function function GetWebConfigVal(){ var hiddenFildsVal=$("#hiddenFiledId").val(); alert(hiddenFildsVal); }
zanussi
  • 1,286
  • 2
  • 22
  • 29
0

If you are using Razor view then this will help

<script type="text/javascript">
var url = '@System.Configuration.ConfigurationManager.AppSettings["pat_ins_suc"]';
alert(url);
</script>
0
<appSettings>
<add key="insert" value="patient inserted successfully"/>
</appSettings>

In the web.config file inside the write this code in the C# code file write the code for calling the JavaScript code

dispay()
{
hdn.Value = ConfigurationManager.AppSettings["insert"];
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", 
"msg()", true);
}

in the .aspx page write the JavaScript function to get the result

<script>
    function msg()
    {
        alert('<%= hdn.Value%>');
    }
</script>

this will display the message that is stored in appsettings of web.config file using the alert function of the JavaScript.