Working with Web User Control

Insert the web user control in ASP.NET

Step 1: Firstly open the visual studio 2010 and click file->new->website->select the ASP.NET website.As shown in the following figure.

Open_project.jpg


Step 2: Now click website->Add New Item->Web User Control,add click on the Add button.


wuc.jpg

 

We can identify this control by the @control directive.

<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>

Step 3: In the designing view of the web user control add some controls like textbox,button,images,linkbutton.like the following image.

Design_part.jpg


Step 4: [Reuse the code and designing of web user control page in another pages].Add some pages in your application.Write the following Register directive in our page.


<%
@ Register TagPrefix="uc1" TagName="menu" Src="~/WebUserControl.ascx" %>


In the <BODY> portion of the file, create a tag for your control where you want the control to appear.
<uc1:menu id="Menu1" runat="server"/>

Step 5: See the designing part of the page,it is same as the web user control.


Summary: You can use this control to reduce the coding as well as designing.So lets try to design it.


 

Ebook Download
View all
Learn
View all