Read Web.Config Connection String Using JavaScript In Asp.Net

This example explains How To Read Web.Config Using JavaScript In Asp.Net.

I am reading Connection String from Web.Config File In onclick Event of html Input Button  through JavaScript function and displaying it in Label.

HTML SOURCE
   1:  <body>
   2:  <form id="form1" runat="server">
   3:  <input id="Button1" type="button" 
   4:         value="Read Web.Config" 
   5:         onclick="ReadWebConfig();"/>
   6:   
   7:  <asp:Label ID="lblReadWebConfig" runat="server" 
   8:             Text=""></asp:Label>
   9:  </form>
  10:  </body>

Write this JAVASCRIPT function in HEAD section of page
   1:  <head runat="server">
   2:  <script type="text/javascript">
   3:      function ReadWebConfig() 
   4:      {
   5:          var connectionString = '<%=ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString %>'
   6:          document.getElementById("lblReadWebConfig").innerHTML = connectionString;
   7:      }
   8:      </script>
   9:  </head>

With this javascript function you can read connection string from web.config file.

If you like this post than join us or share

0 comments:

Find More Articles