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 we talk about web application projects then we simply says that each presentation page attach with code behind page(where you can design your business logic code). If you are a developer and you want to sell your project without code then you will hide its business logic code behind the ".DLL" (dynamic link library) file.
There are available some steps to do this task.
These are
- Create a web application project (file--new project--Visual C# --Web -- ASP.NET web Form application)
- Write project name, which you want, In this article we take "hide code" as a project name.
3. Delete all directories from the solution explorer. Because i want to design only business logic code, after coding we will create DLL file for this. For this you should attach a class file in this project. Take a look after deleted all files from solution explorer.
4. Now, we learn how to attach a class file in the project. Select "add new item" from context menu by right clicking on project name.
Now, here appear a new window. In this window select code in left panel and also select class in the right panel.
5. Write the business logic code for display message on the screen, so we raise a button handler code in displayResult class.
You can design your code for multiple classes through this approach we will create a business logic model. Suppose i want to create a small application for employee, in which i want to display data of employee also display employee salary. Application hold two function first for employee data and second for employee salary. Similarly through this code i want to display "Hello World!" message on the browser. Now your code look like
In the above mentioned snap displayResult class inherits from page class, page class contains some object like response,request etc. if you want to use page objects then created class must be inherits from Page class. Also mentioned two namespace, first is System.Web.UI and other is System.Web.UI.WebControls.
Now your .DLL file has made in Bin folder of the project. File contains single namespace(HideCode) , class(displayResult) and single method(displayresult( )).
7. Now add new project in the solution by right clicking on solution name. Select ASP.NET Web form application project in appeared window also write name of the project, i keep presentation part as a project name. Now your solution explorer contains two project, see below
8. Now add new web form in the project also change the name of it, i keep "presentationpage.aspx" as a project name. This page is basically used for designing purpose. Through this page we can call method of other projects, but will do some changes in the page . Before doing this, first of all add above mentioned project reference in the current project. Learn how to add reference in the project.
(a) Add Reference by right click on References link. select Solution from the appeared window also select .dll checkbox which is appeared in right panel of it.
9. Remove "CodeBehind" attribute from presentation page also add inherits attribute in the page directive. Assign namespace , which is created in earlier project with class name. Look like
10. Add button in the page also raise onclick event on it. Call displayresult( ) method, which is created in business logic code. now your code look like
<%@ Page Language="C#" AutoEventWireup="true" Inherits="HideCode.displayResult" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="hide coding" OnClick ="displayresult" /> </div> </form> </body> </html>
Now your code generate the following output
First code of line define the page directive. In this line,you must to add namespace with class name in inherits attribute. After that you can access methods and properties of that class. In this code i also access method of displayResult class using Button click event.
Comments
Post a Comment