How to read WebConfig Connection Strings & App Settings in Java Script? - Asp.Net

Read Configuration Settings of Web.config using Javascript

Web.config is the main settings and configuration file for an ASP.NET web application. We store application level settings and connection string value in it. In this post I will explain how to read those values from web.config easily. Find the source code below:-

config web,net web application,client side, in java script,aspnet

    <add key="Blog" value="www.etechpulse.com"/>
    <add name="NorthwindConnectionString" connectionString="Data Source=serverName;Initial Catalog=Northwind;Persist Security Info=True;User ID=userName;Password=password" providerName="System.Data.SqlClient" />

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to read Webconfig Connection Strings & App Settings in Java Script - Asp.Net </title>

    <script type="text/javascript">
//    Read appSettings key value from web.config
    function ReadWebConfigappSettings()
           var connectionString = '<%=ConfigurationManager.AppSettings["blog"] %>'
           document.getElementById("lblReadWebConfigappSettings").innerHTML = connectionString;
//    Read connectionStrings from web.config   
    function ReadWebConfigconnectionStrings()
          var connectionString = '<%=ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString %>'
          document.getElementById("lblReadWebConfigconnectionStrings").innerHTML = connectionString;


    <form id="form1" runat="server">
        <input id="btnAS" type="button" value="Read Web.ConfigAppSettings" onclick="ReadWebConfigappSettings();" />
        <input id="btnCS" type="button" value="Read Web.ConfigConnectionStrings" onclick="ReadWebConfigconnectionStrings();" />
        <br />
        <br />
        <asp:Label ID="lblReadWebConfigappSettings" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Label ID="lblReadWebConfigconnectionStrings" runat="server" Text=""></asp:Label>
Download the source code click here ..

How to read WebConfig Connection Strings & App Settings in Java Script? - Asp.Net Reviewed by Ravi Kumar on 11:38:00 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.