简体   繁体   中英

how to display a value that is stored in appsettings of web.config file using javascript?

<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.

try this. i hope this helps

<script type="text/javascript">
    var patinMessage= '<%=ConfigurationManager.AppSettings["pat_ins_suc"]%>';
</script>
  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); }

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>
<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM