简体   繁体   English

如何显示使用JavaScript在web.config文件的appsettings中存储的值?

[英]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. 我想使用一种方法调用在浏览器中使用JavaScript alert()函数显示值。

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. 如何在alert()函数中传递字符串msg,以便它将显示在Web浏览器中。

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. 使用JQuery从隐藏字段中退出。
  3. JQuery function function GetWebConfigVal(){ var hiddenFildsVal=$("#hiddenFiledId").val(); jQuery函数function GetWebConfigVal(){var hiddenFildsVal = $(“#hiddenFiledId”)。val(); alert(hiddenFildsVal); 警报(hiddenFildsVal); } }

If you are using Razor view then this will help 如果您使用的是Razor视图,那么这将有所帮助

<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 在web.config文件内的C#代码文件中编写此代码,编写用于调用JavaScript代码的代码

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 在.aspx页中,编写JavaScript函数以获取结果

<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. 这将显示使用JavaScript的警报功能存储在web.config文件的appsettings中的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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