Prev | Current Page 93 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

mdb"
SelectCommand="SELECT * FROM [Books]">
48 CHAPTER 2 ?–  ENCAPSULATING FUNCT IONALITY IN A SP.NET
Listing 2-2 has the code-behind file for SimpleUserControl.
Listing 2-2. The SimpleUserControl User Control Code-Behind Class File
using System;
using System.Drawing;
namespace ControlsBook2Web.Ch02
{
public partial class SimpleUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public Color HeaderColor
{
get { return GridView1.HeaderStyle.BackColor; }
set { GridView1.HeaderStyle.BackColor = value; }
}
public int RecordsPerPage
{
get { return GridView1.PageSize; }
set { GridView1.PageSize = value; }
}
}
}
SimpleUserControl.aspx provides a test container for our newly created user control
as well as exercises the two custom public properties HeaderColor and RecordsPerPage on
SimpleUserControl.ascx. Listing 2-3 has the source code for the SimpleUserControl demonstration
web form.
Listing 2-3. The SimpleUserControlDemo Web Form .aspx File
<%@ Page Language="C#" MasterPageFile="~/MasterPage/ControlsBook2MasterPage.Master"
AutoEventWireup="true" CodeBehind="SimpleUserControlDemo.aspx.cs"
Inherits="ControlsBook2Web.Ch02.SimpleUserControlDemo"
Title="Simple User Control Demo" %>
<%@ Register Src="SimpleUserControl.


Pages:
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105