ASP.NET UserControl by VB.NET

In this article we will see how to create user control and how to use it in our web forms.
  • 2946

In this article, we will see how to create a user control for ASP.NET. A user control is a custom, reusable control in ASP.NET, saved in a file with an extension.ascx. you can reuse the Design as well as code in the application With the help of the user control. They cannot run on their own and they need to stand on another platform like an aspx page. Web user controls are derived from System.Web .UI.User Control namespace.

Step 1:

Create a new ASP .Net web application using Visual Studio .Net. 



Step 2:

Add a Web User Control to the project. Name it as UserControl1.ascx.

now select project and right click on it. 



Now select Add new Item.



Now click on the Add button.

Step 3:

Now add the following code with the webusercontrol1.ascx. Add two Textbox to the User Control as follows.

<div style ="border-left: 1px solid green; border-right: 1px solid green; border-bottom: 1px solid green; border-top: 20px solid green; width:309px;  ">

              <br />     

    login: <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>        

        <br />       

        password: <asp:TextBox ID="TextBox2"

            runat="server" Width="147px"></asp:TextBox>           

        <br />

        <br />



Step 4:


Drag and drop the WebUserControl1.ascx into the Web form. This will put the following entries in the aspx page.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"Inherits="webusercontrol.WebForm1" %>

 <%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""">


<html xmlns="">

<head runat="server">




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



    <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />




Now build and run the application. 




As we have seen in this example, user controls can be built once and re-used any number of times as required in the same web page, web site or even across multiple web sites.


In this article we have seen how to create user control and how to use it in our web forms.


More Articles

© 2020 DotNetHeaven. All rights reserved.