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 }); }
If you want to add event at run time like click event in page load method. For this types of problem you can use EventHandler class. Create a object of this class also pass new method as a parameter.
<asp:Button ID="B1" runat="server" CommandName="Add" Text="Button" />
</div>
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
B1.Click += new System.EventHandler(this.calculate);
}
protected void calculate(object sender, System.EventArgs e)
{
switch (((Button)sender).CommandName)
{
case "Add": Response.Write("hello");
break;
}
}
}
Code Generate the following output
Source Code
<div><asp:Button ID="B1" runat="server" CommandName="Add" Text="Button" />
</div>
Business Code
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
B1.Click += new System.EventHandler(this.calculate);
}
protected void calculate(object sender, System.EventArgs e)
{
switch (((Button)sender).CommandName)
{
case "Add": Response.Write("hello");
break;
}
}
}
Code Generate the following output
Comments
Post a Comment