How to set property value of a control in ASP.net using Web.config in web form
How can I set the value of a property in an ASP.net control? Suppose my control is:
<asp:Label runat="Server" ID="Label1" Text="Value"></asp:Label>
I want to get Value
from web.config:
System.Configuration.ConfigurationManeger.AppSetting["ValueKey"]
What should I do?
I apologize for bad and bad english.
+3
Seyed morteza mousavi
source
to share
3 answers
Try it -
<asp:Label ID="Label1" runat="server" Text='<%$ AppSettings:SettingKey%>'></asp:Label>
Where SettingKey is the key name of your appsetting.
+1
dynamicuser
source
to share
Try -
C #: Label1.Text = System.Configuration.ConfigurationManager.AppSettings ["ValueKey"]. ToString ()
VB: Label1.Text = System.Configuration.ConfigurationManager.AppSettings ("ValueKey"). ToString ()
0
dynamicuser
source
to share
Add the code to load the page as follows: -
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.Configuration.ConfigurationManager.AppSettings["ValueKey"].ToString();
}
0
Harshit Tailor
source
to share