<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="PropertyTester" %>
<!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" >
<head runat="server">
<title>Server Control Property Tester</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Server Control Property Tester</h1>
<asp:Panel ID="panChange" runat="server"
GroupingText="Controls that will change">
<asp:Label id="labHere" runat="server">Here is a label</asp:Label>
<asp:TextBox id="txtBox" runat="server">Sample Text</asp:TextBox>
<asp:Label id="labAnother" runat="server">This is yet another label</asp:Label>
<asp:Button id="btnSample" runat="server" Text="Sample Button"></asp:Button>
</asp:Panel>
<asp:Panel ID="panProperties" runat="server"
GroupingText="When you choose these display properties">
<br/><asp:CheckBox id="chkVisible" runat="server" Text="Visible" AutoPostBack="True" Checked="True" OnCheckedChanged="chkVisible_CheckedChanged"></asp:CheckBox>
<br/><asp:CheckBox id="chkEnabled" runat="server" Text="Enabled" AutoPostBack="True" Checked="True" OnCheckedChanged="chkEnabled_CheckedChanged"></asp:CheckBox>
<br/>Text Color:
<asp:DropDownList id="drpTextColor" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpTextColor_SelectedIndexChanged">
<asp:ListItem Value="0" Selected="True">Choose a color</asp:ListItem>
<asp:ListItem Value="Black">Black</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="CadetBlue">Cadet Blue</asp:ListItem>
<asp:ListItem Value="Firebrick">Firebrick</asp:ListItem>
<asp:ListItem Value="Gainsboro">Gainsboro</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Gold">Gold</asp:ListItem>
<asp:ListItem Value="LimeGreen">Lime Green</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="SaddleBrown">Saddle Brown</asp:ListItem>
<asp:ListItem Value="Violet">Violet</asp:ListItem>
<asp:ListItem Value="Yellow">Yellow</asp:ListItem>
</asp:DropDownList>
<br/>Background Color:
<asp:DropDownList id="drpBackgroundColor" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpBackgroundColor_SelectedIndexChanged">
<asp:ListItem Value="0" Selected="True">Choose a color</asp:ListItem>
<asp:ListItem Value="Black">Black</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="CadetBlue">Cadet Blue</asp:ListItem>
<asp:ListItem Value="Firebrick">Firebrick</asp:ListItem>
<asp:ListItem Value="Gainsboro">Gainsboro</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Gold">Gold</asp:ListItem>
<asp:ListItem Value="LimeGreen">Lime Green</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="SaddleBrown">Saddle Brown</asp:ListItem>
<asp:ListItem Value="Violet">Violet</asp:ListItem>
<asp:ListItem Value="Yellow">Yellow</asp:ListItem>
</asp:DropDownList>
<br/>Font:
<asp:DropDownList id="drpFont" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpFont_SelectedIndexChanged">
<asp:ListItem Value="Choose a font">Choose a font</asp:ListItem>
<asp:ListItem Value="Arial">Arial</asp:ListItem>
<asp:ListItem Value="Times New Roman">Times New Roman</asp:ListItem>
<asp:ListItem Value="Tahoma">Tahoma</asp:ListItem>
</asp:DropDownList>
<br/>Font Size:
<asp:DropDownList id="drpFontSize" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpFontSize_SelectedIndexChanged">
<asp:ListItem Value="Choose a font size" Selected="True">Choose a font size</asp:ListItem>
<asp:ListItem Value="10">10pt</asp:ListItem>
<asp:ListItem Value="14">14pt</asp:ListItem>
<asp:ListItem Value="16">16pt</asp:ListItem>
</asp:DropDownList>
<br/>Border Style:
<asp:DropDownList id="drpBorderStyle" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpBorderStyle_SelectedIndexChanged">
<asp:ListItem Value="Choose a border style" Selected="True">Choose a border style</asp:ListItem>
<asp:ListItem Value="dashed">dashed</asp:ListItem>
<asp:ListItem Value="inset">inset</asp:ListItem>
<asp:ListItem Value="none">none</asp:ListItem>
<asp:ListItem Value="outset">outset</asp:ListItem>
<asp:ListItem Value="solid">solid</asp:ListItem>
</asp:DropDownList>
<br/>Border Width:
<asp:DropDownList id="drpBorderWidth" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpBorderWidth_SelectedIndexChanged">
<asp:ListItem Value="Select a border width" Selected="True">Select a border width</asp:ListItem>
<asp:ListItem Value="1">1 px</asp:ListItem>
<asp:ListItem Value="2">2 px</asp:ListItem>
<asp:ListItem Value="3">3 px</asp:ListItem>
</asp:DropDownList>
</asp:Panel>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class PropertyTester : System.Web.UI.Page
{
private Style _styleToApply = new Style();
protected void chkVisible_CheckedChanged(object sender, EventArgs e)
{
if (chkVisible.Checked)
ChangeVisible(true);
else
ChangeVisible(false);
}
protected void chkEnabled_CheckedChanged(object sender, EventArgs e)
{
if (chkEnabled.Checked)
ChangeEnabled(true);
else
ChangeEnabled(false);
}
protected void drpTextColor_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpTextColor.SelectedIndex > 0)
{
_styleToApply.ForeColor = Color.FromName(drpTextColor.SelectedValue);
ApplyNewStyle(_styleToApply);
}
}
protected void drpBackgroundColor_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpBackgroundColor.SelectedIndex > 0)
{
_styleToApply.BackColor = Color.FromName(drpBackgroundColor.SelectedValue);
ApplyNewStyle(_styleToApply);
}
}
protected void drpFont_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpFont.SelectedIndex > 0)
{
_styleToApply.Font.Name = drpFont.SelectedValue;
ApplyNewStyle(_styleToApply);
}
}
protected void drpFontSize_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpFontSize.SelectedIndex > 0)
{
int fontSize = Convert.ToInt32(drpFontSize.SelectedValue);
_styleToApply.Font.Size = FontUnit.Point(fontSize);
ApplyNewStyle(_styleToApply);
}
}
protected void drpBorderStyle_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpBorderStyle.SelectedIndex > 0)
{
string currBorderStyle = drpBorderStyle.SelectedValue;
if (currBorderStyle == "dashed")
_styleToApply.BorderStyle = BorderStyle.Dashed;
else if (currBorderStyle == "inset")
_styleToApply.BorderStyle = BorderStyle.Inset;
else if (currBorderStyle == "none")
_styleToApply.BorderStyle = BorderStyle.None;
else if (currBorderStyle == "outset")
_styleToApply.BorderStyle = BorderStyle.Outset;
else if (currBorderStyle == "solid")
_styleToApply.BorderStyle = BorderStyle.Solid;
ApplyNewStyle(_styleToApply);
}
}
protected void drpBorderWidth_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpBorderWidth.SelectedIndex > 0)
{
int borderSize = Convert.ToInt32(drpBorderWidth.SelectedValue);
_styleToApply.BorderWidth = Unit.Pixel(borderSize);
ApplyNewStyle(_styleToApply);
}
}
private void ApplyNewStyle(Style styleToSet)
{
labHere.ApplyStyle(styleToSet);
labAnother.ApplyStyle(styleToSet);
txtBox.ApplyStyle(styleToSet);
btnSample.ApplyStyle(styleToSet);
}
private void ChangeVisible(bool which)
{
labHere.Visible = which;
labAnother.Visible = which;
txtBox.Visible = which;
btnSample.Visible = which;
}
private void ChangeEnabled(bool which)
{
labHere.Enabled = which;
labAnother.Enabled = which;
txtBox.Enabled = which;
btnSample.Enabled = which;
}
}
|