User control with readonly properties : Property « User Control and Master Page « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » User Control and Master Page » Property 
User control with readonly properties

<%@ Page %>
<%@ Register TagPrefix="uc1" TagName="header" Src="Control.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <title>User Controls</title>
    <Script language="C#" Runat="Server">
      private void Page_Load(object sender, System.EventArgs e)
    {
      header1.Author = "Snoopy";
      FooterLabel.Text = "Rendered " + header1.RenderDate;
    }
    </Script>
  </HEAD>
  <body>
    <form id="dependingdropdowns" method="post" runat="server">
      <uc1:header id="header1" runat="server" Title="A Tale of Mystery"></uc1:header>
      <p>It was a dark and stormy night.</p>
      <hr/>
      <asp:Label ID="FooterLabel" Runat="server" />
    </form>
  </body>
</HTML>

File: Control.ascx

<%@ Control Language="c#" %>
<script runat="server">
private string title;
private string author;
private DateTime renderDate = System.DateTime.Now;

public string Title {
  get {
    return title;
  }
  set {
    title = value;
  }
}
public string Author {
  get {
    return author;
  }
  set {
    author = value;
  }
}

// ReadOnly

public DateTime RenderDate {
  get {
    return renderDate;
  }
}

private void Page_Load(object sender, EventArgs e)
{
  TitleLabel.Text = Title;
  AuthorLabel.Text = Author;  
}
</script>
<h1><asp:Label id="TitleLabel" runat="server" /></h1>
<h3><asp:Label id="AuthorLabel" runat="server" /></h1>

 
Related examples in the same category
1.Creating ViewState-Enabled Control Properties (C#)
2.Creating ViewState-Enabled Control Properties (VB)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.