C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

UserControl Tutorial : Create ,Register and use of usercontrol in asp.net with example and code

♠ Posted by Unknown in , at Wednesday, February 11, 2015



Tutorial Of Asp.Net UserControl


Definition of UserControl in Asp.Net :

In Asp.Net Web server controls , you can create your own custom, reusable controls using following step. These controls are called user controls.

A user control is a kind of composite control that works much like an ASP.NET other server control . you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages like same as other server control.



For create asp.net usercontrol using c# following step perform





Step 1: First of all add one folder in your website or project for contain all user control as follow screen.

Step 2:Right Click on folder in which you want to contain usercontrol as follow screen.

Step 3: Select web user control , give proper name and click to add button as follow screen



Step 4 : after add you can see your control in your project or website as follow screen:


Step 5: Now you need to add code in .ascx page as per your required control as follow screen:

Code For Simple Text box control make as userdefine control you set property once in user define control then you no need to write again only need to register control on your page and use it. Following code in .ascx page.

<asp:TextBox ID="TextBox1" runat="server" BackColor="WhiteSmoke" BorderColor="ActiveBorder"
    Font-Bold="true" Font-Size="X-Large" ForeColor="Aqua" Height="70px" TextMode="MultiLine" runat="server"
    Width="100px"></asp:TextBox>
Now your control is ready to use.

Step 6: Add following code to register user control in your webpage in second line:


<%@ Register Src="~/Control/UserDefineTextBoxWebUserControl.ascx" TagName="TextBox" TagPrefix="My" %>

Step 6: Now code for use control in your page at content as follow:

<My:TextBox ID="mytextbox1" runat="server" />

See here no need to set any property and you get output as follow:


This way you can make any server control to your own control such as linkbutton, Dropdown, checkbox, radiobutton, etc.


Improve Your Answer as comment below.
If our post is useful please share and comment on our post for more post and detail Visit :

http://aspdotnethelpmaster.blogspot.in/

0 comments:

Post a Comment