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:
<add key="Chandu" value=" Hi "/>
<add name="HkConnectionString" connectionString="Data Source= Sql2k8;Initial Catalog=hkburaDB;Integrated Security=True;"/>
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 %>'
var hk = '<%=ConfigurationManager.AppSettings["Chandu"].ToString() %>'
 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