Explain about ASP.Net Web forms

It is possible to build re-usable code on ASP.Net. In certain places, the re-usable code can be used without the need to write the code again.

After writing the code, the re-usable code helps to minimize the amount of time spent by the developer. It can be performed once at different locations and reused.

Creating ASP.Net User Access

The capacity of ASP .Net online training is to build Web controls. Such controls contain code that can be used again. As per the requirement, it can be used in the application.

Let's look at an example of how we can build control for web users in ASP.Net.

In our illustration,

We are going to build a control system for the web.

A header component will be generated using it.

Let's work in the earlier sections with our new web application developed. Let's follow the steps below to create a control for a Web user.

Step 1)

The first step is to build and add to our Visual Studio Solution web user access.

Creating controls for Asp.net, Webforms, and Web config files

In Visual Studio, go to Solution Explorer and right-click on DemoApplication Solution.

Choose an Add->New Item in the menu item.

Step 2)

In the next step, we must choose to build a web user control option.

  • We can see different options for building various kinds of components in the project dialog box. On the left-hand side, click the "Web" option.
  • When we click on the "Web" button, the "Web Forms User control." option appears. Click on this option for more Dot net training.
  • We then assign the name "Control" to the web control.
  • Finally, to let Visual Studio add a web user control to our solution, press the 'Add' button.

Step 3)

Now it's time to install the Site User Control custom code. Pure HTML syntax will be the foundation of our code. Add the following code to the code.

<table>

<tr>

<td> Tutorials</td>

</tr>

<tr>

<td> This Tutorial is for</td>

</tr>

</table>

Explanation of Code:

In our Web Control file, we construct a table element first. This will be used to keep 2 text rows that will be used for showing the above code result.

NOTE:

We are now unable to run this code and display the production. The only way to see if it works is to use it in our app (aspx file).In the following subject, we are going to look into this.

Registration of ASP.NET Web Form User Controls

We have seen how we can build a custom web control in the earlier section. This can be used in a web form to show the two following lines.

We need to use it in our web application once the custom 'control' is developed. The first step is to have the element registered in our application (Demo.aspx). This is the prerequisite for any custom web control to be used in an ASP.Net application.

Let's discuss how we can accomplish this. The steps below are a continuation of the previous chapter. We built our custom control in the previous section. We'll be using the control in our Demo.aspx web form in this section.

Second, our custom 'control' will be recorded in the Demo.aspx format.

Step 1)

Ensure that the demo.aspx file is being worked on. It is in this file that the control of the web user is documented. This can be achieved in the Solution Explorer of your .Net solution by double-clicking the demo.aspx file.

You will definitely see the code below in the form until you double-click the form. When a web form is applied to an ASP.Net project, this is the default code added by Visual Studio.

The default code consists of steps that are necessary to ensure that the form will run in the browser as an ASP.Net Webform.

Step 2)

Now, let's add our code to the user control register.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="DemoApplication.Demo" %>

<%@ Register Src="~/Control.ascx" TagName="WebControl" TagPrefix="TWebControl"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.ore/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="forml" runat="server”>

<TWebControl:WebControl ID="Header" runat="server" />

</form>

</body>

</html>

Explanation of Code:

The first step is to document the control of the site user. This includes the basic parameters below.

  • To record the control of the site user, the 'Register' keyword is used.
  • The src parameter is used to describe, in our case, the control name.
  • Individual names given to the control are the tagname and Tagprefix. This is achieved so that they can be referenced as a standard HTML control in HTML pages.

Next, through the TagPrefix: TagName that was assigned earlier, we refer to our Web user access. TagPrefix: TagName is an indication that our custom site control is what we want to use.

  • "The optional ID is given to the "Header" control. Giving an ID to an HTML control is normally a good practice.
  • Finally, the attribute runat=server is used so that the control runs on the webserver. This is the default attribute for all ASP.Net controls. It is important to run all ASP.Net controls (including custom controls) on the server. Their output is then sent to the client from the server and is displayed accordingly in the browser.
  • When the above code is set and the project uses Visual Studio to execute. You'll get the production below.

Registering asp.net globally in the asp configuration file for the site

configuration

Often, in a .Net program, one would want to use user controls on many sites. You don't want to keep on documenting user controls on each and every ASP.Net page at this point.

  • You can register with .Net on the 'web.config' file.
  • The site.config file is a standard configuration file used in the .Net project for all web pages.
  • It includes the configuration information needed for the ASP.Net web project. For instance,

the target framework parameter is one common configuration in the web.config file.

  • This parameter is used to define the version of the .Net system the application uses.

Let's see how we can register our web.config control in the code.

Step 1)

By double-clicking the file, open the web.config file from the solution explorer.

You might see the below configuration when you open the web.config file. When the project is built, Visual Studio automatically adds 'web.config'. To make the ASP.Net project work properly, this is the basic configuration needed.

Step 2)

Now let's register the web.config file with our part. For that, we need to add the lines below.

<configuration>

<system.web>

<compilation debug="true" targetFramework="4.5" />

<pages>

<controls>

<add tagPrefix="TWebControl" src ="~/Control.ascx" tagName="WebControl"/>

</controls>

</pages>

</system.web>

</configuration>

The registration contains the sub-stages below.

Attach the <pages> tag. This means that all the control settings would be available to all of the solution's ASP.Net sites.

The <controls> tag indicates that you are implementing a user control setup.

Then, with the additional tag, we record the user power. The remaining tagPrefix, tagName, and src parameters remain the same as before.

Step 3)

Remember to go to the page 'demo.aspx' and delete the control lines that had the part registration. If you do not perform this Step, a file will be executed instead of the file 'web.config' from the file 'demo.aspx.'

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="DemoApplication.Demo" %>

<%@ Register Src="~/Control.ascx" TagName="WebControl" TagPrefix="TWebControl"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.ore/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server”>

<TWebControl:WebControl ID="Header" runat="server" />

</form>

</body>

Conclusion

ASP.Net has the ability to construct controls for users. To provide code that is used several times in an application, user controls are used. It is then possible to reuse the user control in the program. Before it can be used, the user control needs to be documented on the ASP.Net website. Then there is Asp .Net online training India for you to know more.