Wednesday, 6 April 2011

Read Configuration Settings of Web.config using Javascript




1.Add the following Code entries in the file between the <configuration> tag as shown below:
<configuration>
<appSettings>
<add key="Chandu" value=" Hi "/>
</appSettings>
<connectionStrings>
<add name="HkConnectionString" connectionString="Data Source= Sql2k8;Initial Catalog=hkburaDB;Integrated Security=True;"/>
</connectionStrings>
...
<configuration>
2.We will now read these Values using JavaScript. To do so, add the following script in the <head> tag of your   page as shown below:
<script type="text/javascript">
function ReadConfigSettings()
{
var Con= '<%=ConfigurationManager.ConnectionStrings["HkConnectionString"].ConnectionString %>'
alert(Con);
var hk = '<%=ConfigurationManager.AppSettings["Chandu"].ToString() %>'
alert(hk);
}
</script>
 3.Call this function on a button click and display the values of the configuration settings
 <asp:Button ID="btnclick" runat="server" Text="Click" OnClientClick="ReadConfigSettings()" />






   
 

No comments:

Post a Comment