Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> ASP.Net & Web Forms >> Creating User Define Control in ASP .Net
Creating User Define Control in ASP .Net
Creating User Define Control in ASP .Net


by Anurag Chaurasia on 2/16/2011 8:10:56 PM

Views: 4034       Comments: 0

Creating User Define Control in ASP .Net

Step:

·         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:

Code:

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

<table style="width: 330px">

    <tr>

        <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>

    </tr>

    <tr>

        <td style="height: 55px" align="center">

            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></td>

    </tr>

</table>

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.

Code:

<%@ 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

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

<!—You can use that control by using that code -- >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

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

    <div>

    <shw:ShowData runat="server"  ID="sh1"/>

    </div>

    </form>

</body>

</html>

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

 

 

 

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Anurag ChaurasiaRSS Feed
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2948
Advertisement
MindStick Cleaner
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.