Search This Blog

Oct 14, 2012

User Control Example

In this example I show that how easily we can create User Control and then use it in Here first I create a User Control name CalendarUserControl.ascx, then place it Default.aspx web form. Here is the source code of both files.

<%@ Control Language="C#" ClassName="CalendarUserControl" %> 
<script runat="server"> 
    protected void Calendar1_SelectionChanged(object sender, System.EventArgs e) { 
        Label1.Text = "Your selected Date is: " + 
<h2>This is user control</h2> 
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="DarkGreen"></asp:Label> 
<br /><br /> 
<asp:Calendar ID="Calendar1" runat="server" BackColor="Beige" OnSelectionChanged="Calendar1_SelectionChanged"> 

<%@ Page Language="C#" %> 
<%@ Register src="CalendarUserControl.ascx" tagname="CalendarUserControl" tagprefix="uc1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
<script runat="server"> 
<html xmlns=""> 
<head runat="server"> 
    <title>User Control Example: how to create and use User Control in</title> 
    <form id="form1" runat="server"> 
        <h1 style="color:Red;">This is page top</h1> 
        <hr /> 
        <uc1:CalendarUserControl ID="CalendarUserControl1" runat="server" /> 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...