本文整理汇总了C#中System.Web.UI.WebControls.WebParts.IWebEditable接口的典型用法代码示例。如果您正苦于以下问题:C# IWebEditable接口的具体用法?C# IWebEditable怎么用?C# IWebEditable使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IWebEditable接口属于System.Web.UI.WebControls.WebParts命名空间,在下文中一共展示了IWebEditable接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEditorParts
//引入命名空间
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class TextDisplayWebPart : WebPart
{
private String _contentText = null;
private String _fontStyle = null;
TextBox input;
Label DisplayContent;
Literal lineBreak;
public override EditorPartCollection CreateEditorParts()
{
ArrayList editorArray = new ArrayList();
TextDisplayEditorPart edPart = new TextDisplayEditorPart();
edPart.ID = this.ID + "_editorPart1";
editorArray.Add(edPart);
EditorPartCollection editorParts =
new EditorPartCollection(editorArray);
return editorParts;
}
public override object WebBrowsableObject
{
get { return this; }
}
[Personalizable(), WebBrowsable]
public String ContentText
{
get { return _contentText; }
set { _contentText = value; }
}
[Personalizable(), WebBrowsable()]
public String FontStyle
{
get { return _fontStyle; }
set { _fontStyle = value; }
}
protected override void CreateChildControls()
{
Controls.Clear();
DisplayContent = new Label();
DisplayContent.BackColor = Color.LightBlue;
DisplayContent.Text = this.ContentText;
if (FontStyle == null)
FontStyle = "None";
SetFontStyle(DisplayContent, FontStyle);
this.Controls.Add(DisplayContent);
lineBreak = new Literal();
lineBreak.Text = @"<br />";
Controls.Add(lineBreak);
input = new TextBox();
this.Controls.Add(input);
Button update = new Button();
update.Text = "Set Label Content";
update.Click += new EventHandler(this.submit_Click);
this.Controls.Add(update);
}
private void submit_Click(object sender, EventArgs e)
{
// Update the label string.
if (!string.IsNullOrEmpty(input.Text))
{
_contentText = input.Text + @"<br />";
input.Text = String.Empty;
DisplayContent.Text = this.ContentText;
}
}
private void SetFontStyle(Label label, String selectedStyle)
{
if (selectedStyle == "Bold")
{
label.Font.Bold = true;
label.Font.Italic = false;
label.Font.Underline = false;
}
else if (selectedStyle == "Italic")
{
label.Font.Italic = true;
label.Font.Bold = false;
label.Font.Underline = false;
}
else if (selectedStyle == "Underline")
{
label.Font.Underline = true;
label.Font.Bold = false;
label.Font.Italic = false;
}
else
{
label.Font.Bold = false;
label.Font.Italic = false;
label.Font.Underline = false;
}
}
// Create a custom EditorPart to edit the WebPart control.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
private class TextDisplayEditorPart : EditorPart
{
DropDownList _partContentFontStyle;
public override bool ApplyChanges()
{
TextDisplayWebPart part =
(TextDisplayWebPart)WebPartToEdit;
// Update the custom WebPart control with the font style.
part.FontStyle = PartContentFontStyle.SelectedValue;
return true;
}
public override void SyncChanges()
{
TextDisplayWebPart part =
(TextDisplayWebPart)WebPartToEdit;
String currentStyle = part.FontStyle;
// Select the current font style in the drop-down control.
foreach (ListItem item in PartContentFontStyle.Items)
{
if (item.Value == currentStyle)
{
item.Selected = true;
break;
}
}
}
protected override void CreateChildControls()
{
Controls.Clear();
// Add a set of font styles to the dropdown list.
_partContentFontStyle = new DropDownList();
_partContentFontStyle.Items.Add("Bold");
_partContentFontStyle.Items.Add("Italic");
_partContentFontStyle.Items.Add("Underline");
_partContentFontStyle.Items.Add("None");
Controls.Add(_partContentFontStyle);
}
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write("<b>Text Content Font Style</b>");
writer.WriteBreak();
writer.Write("Select a font style.");
writer.WriteBreak();
_partContentFontStyle.RenderControl(writer);
writer.WriteBreak();
}
// Access the drop-down control through a property.
private DropDownList PartContentFontStyle
{
get
{
EnsureChildControls();
return _partContentFontStyle;
}
}
}
}
}