0

I am wanting to pull text from web.config. I have added the following code <add key ="AssignedToText" value="Please submit a ticket to assign any users to this specific group."/>to my web.config file. I want to display this text on the bottom of an ascx page. How can i go about doing so? How do code it into the ascx.cs file and how do I code it onto the ascx file

1 Answers1

1

Use the ConfigurationManager to get keys from the web.config like this:

public string AssignedToText = ConfigurationManager.AppSettings["AssignedToText"];

Then in your .ascx page you can do this:

<%= AssignedToText %>
Omar Himada
  • 2,540
  • 1
  • 14
  • 31
  • public string AssignedToText = ConfigurationManager.AppSettings["AssignedToText"]; do i add this to the Page_Load – inderpreet lahil Aug 08 '19 at 18:19
  • Declare it at the class level by making it `public string ...` in your `.ascx.cs` file, then your `.ascx` page will be able to see it. Set the value in Page_Load if you want, doesn't matter, so long as variable is declared at class level of the user control – Omar Himada Aug 08 '19 at 18:40
  • Works like a charm! Thank you so much – inderpreet lahil Aug 08 '19 at 18:42