•   Open a Blank Default.aspx page from visual studio 2005.
  •   Go to the solution explorer and right click on to the Default.aspx and then click on the Add New Item.
  •   After that you have to select the Web User Control.ascx file from add new item dialog box.
  •   That page will be the same like as default asp page draw your user control on that page.
  •   Code on the User Control.ascx page:
 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<table style="width: 330px">
        <td style="height: 148px" align="center">
            <asp:Label ID="Label1" runat="server" Text="Thanks To awadh Sir" Font-Bold="True" Font-Size="XX-Large" ForeColor="Red" Visible="False"></asp:Label></td>
        <td style="height: 55px" align="center">
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td>
Design View of User Control:

User Define Control in ASP .Net

After making your user control you have to go on the Source view of Design Page and add that code in the start of your page.

 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"  Inherits="_Default" %>
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="shw" TagName="ShowData" %>
<!-- This is how use to declare and use a user control on your web page -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<!—You can use that control by using that code -- >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <shw:ShowData runat="server"  ID="sh1"/>

After that when you will add and click on to the button there will be a text which will diplay on your web form……


  Modified On Nov-29-2017 12:50:09 PM

Leave Comment