I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
Today i am writing ado.net code in code behind file, On that time i notice that if i take my connection string in the web.config file then we can access it easily. But how? So i have search in msdn library to access the web.config file then i found ConfigurationManager class which is available in System.Configuration Namespace. Through this class we can get all elements of web.config file. Lets take a simple example.
Web.config file
<appSettings>
<add key="jacob" value="My Name"/>
</appSettings>
Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Readwebxmlfile.aspx.cs" Inherits="Readwebxmlfile" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
<asp:Button ID="Button1" runat="server" Height="57px" OnClick="Button1_Click" Text="Get Data from Application Setting" Width="232px" />
</form>
</body>
</html>
Code Behind Code
using System.Configuration;
protected void Button1_Click(object sender, EventArgs e)
{
String getname = ConfigurationManager.AppSettings["jacob"].ToString();
Label1.Text = getname;
}
Here we access AppSettings By the configurationManager class. You can access all property or elements from web.config file by using this class. Now the simple syntax to access them.
ConfigurationManager.elementName
Web.config file
<appSettings>
<add key="jacob" value="My Name"/>
</appSettings>
Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Readwebxmlfile.aspx.cs" Inherits="Readwebxmlfile" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
<asp:Button ID="Button1" runat="server" Height="57px" OnClick="Button1_Click" Text="Get Data from Application Setting" Width="232px" />
</form>
</body>
</html>
Code Behind Code
using System.Configuration;
protected void Button1_Click(object sender, EventArgs e)
{
String getname = ConfigurationManager.AppSettings["jacob"].ToString();
Label1.Text = getname;
}
Here we access AppSettings By the configurationManager class. You can access all property or elements from web.config file by using this class. Now the simple syntax to access them.
ConfigurationManager.elementName
Comments
Post a Comment