PartChromeState Enumeration
Assembly: System.Web (in system.web.dll)
The following code examples demonstrate the declarative use of the PartChromeState enumeration by using a custom WebPart control referenced in an ASP.NET Web page. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control.
The first part of the example contains the code for the custom control, named TextDisplayWebPart. Because the control derives from WebPart, it also inherits the common properties that the Part class provides, including the ChromeState property, which uses the PartChromeState enumeration as its return type.
package Samples.AspNet.JSL.Controls;
import System.*;
import System.Security.Permissions.*;
import System.Web.*;
import System.Web.UI.WebControls.*;
import System.Web.UI.WebControls.WebParts.*;
/** @attribute AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal)
*/
/** @attribute AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
AspNetHostingPermissionLevel.Minimal)
*/
public class TextDisplayWebPart extends WebPart
{
private String _contentText = null;
private TextBox input;
private Label displayContent;
private String _subTitle = "Contoso, Ltd";
public TextDisplayWebPart()
{
this.set_AllowClose(false);
} //TextDisplayWebPart
/** @attribute Personalizable(PersonalizationScope.User, true)
@attribute WebBrowsable()
*/
/** @property
*/
public String get_ContentText()
{
return _contentText;
} //get_ContentText
/** @property
*/
public void set_ContentText(String value)
{
_contentText = value;
} //set_ContentText
protected void CreateChildControls()
{
get_Controls().Clear();
displayContent = new Label();
displayContent.set_BackColor(System.Drawing.Color.get_LightBlue());
displayContent.set_Text(this.get_ContentText());
this.get_Controls().Add(displayContent);
input = new TextBox();
this.get_Controls().Add(input);
Button update = new Button();
update.set_Text("Set Label Content");
update.add_Click(new EventHandler(this.Submit_Click));
this.get_Controls().Add(update);
set_ChildControlsCreated(true);
} //CreateChildControls
private void Submit_Click(Object sender, EventArgs e)
{
// Update the label string.
if (!(input.get_Text().Equals(""))) {
this.set_ContentText(
this.get_Page().get_Server().HtmlEncode(input.get_Text())
+ "<br />");
// Clear the input textbox.
input.set_Text("");
displayContent.set_Text(this.get_ContentText());
}
} //Submit_Click
} //TextDisplayWebPart
Note that in the declarative markup for the Web page, the second instance of the TextDisplayWebPart control sets its ChromeState property. After you load the page in a browser, the second control instance appears minimized.
<%@ page language="VJ#" %>
<%@ register tagprefix="aspSample"
Namespace="Samples.AspNet.JSL.Controls"
Assembly="TextDisplayWebPartJSL" %>
<html>
<head id="Head1" runat="server">
</head>
<body>
<form id="Form1" runat="server">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<asp:webpartzone
id="WebPartZone1"
runat="server"
backcolor="#99cccc">
<parttitlestyle font-bold="true" forecolor="#ffffff" />
<partstyle
borderwidth="1px"
borderstyle="Solid"
bordercolor="#81AAF2" />
<zonetemplate>
<aspSample:TextDisplayWebPart
runat="server"
id="textwebpart"
title = "Text Content WebPart"
Description="A text content WebPart control."
ChromeType="TitleAndBorder"
width="350px" />
</zonetemplate>
</asp:webpartzone>
<asp:webpartzone
id="WebPartZone2"
runat="server"
backcolor="#99cccc">
<parttitlestyle font-bold="true" forecolor="#ffffff" />
<partstyle
borderwidth="1px"
borderstyle="Solid"
bordercolor="#81AAF2" />
<zonetemplate>
<aspSample:TextDisplayWebPart
runat="server"
id="textwebpart2"
title = "Text Content WebPart 2"
Description="A text content WebPart control."
ChromeType="TitleOnly"
ChromeState="Minimized"
width="350px" />
</zonetemplate>
</asp:webpartzone>
</form>
</body>
</html>
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.