本文整理汇总了C#中System.Web.UI.WebControls.WebParts.IPersonalizable接口的典型用法代码示例。如果您正苦于以下问题:C# IPersonalizable接口的具体用法?C# IPersonalizable怎么用?C# IPersonalizable使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IPersonalizable接口属于System.Web.UI.WebControls.WebParts命名空间,在下文中一共展示了IPersonalizable接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateChildControls
namespace Samples.AspNet.CS.Controls
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class UrlListWebPart : WebPart, IPersonalizable
{
private ArrayList _sharedUrls;
private ArrayList _userUrls;
private bool _listDirty;
private TextBox _nameTextBox;
private TextBox _urlTextBox;
private Button _addButton;
private BulletedList _list;
protected override void CreateChildControls()
{
Label nameLabel = new Label();
Label urlLabel = new Label();
LiteralControl breakLiteral1 = new LiteralControl("<br />");
LiteralControl breakLiteral2 = new LiteralControl("<br />");
LiteralControl breakLiteral3 = new LiteralControl("<br />");
_nameTextBox = new TextBox();
_urlTextBox = new TextBox();
_addButton = new Button();
_list = new BulletedList();
nameLabel.Text = "Name: ";
urlLabel.Text = "URL: ";
_nameTextBox.ID = "nameTextBox";
_urlTextBox.ID = "urlTextBox";
_addButton.Text = "Add";
_addButton.ID = "addButton";
_addButton.Click += new EventHandler(this.OnClickAddButton);
_list.DisplayMode = BulletedListDisplayMode.HyperLink;
_list.ID = "list";
Controls.Add(nameLabel);
Controls.Add(_nameTextBox);
Controls.Add(breakLiteral1);
Controls.Add(urlLabel);
Controls.Add(_urlTextBox);
Controls.Add(breakLiteral2);
Controls.Add(_addButton);
Controls.Add(breakLiteral3);
Controls.Add(_list);
}
private void OnClickAddButton(object sender, EventArgs e)
{
string name = _nameTextBox.Text.Trim();
string url = _urlTextBox.Text.Trim();
Pair p = new Pair(name, url);
if (WebPartManager.Personalization.Scope == PersonalizationScope.Shared)
{
_sharedUrls ??= new ArrayList();
_sharedUrls.Add(p);
}
else
{
_userUrls ??= new ArrayList();
_userUrls.Add(p);
}
OnUrlAdded();
}
protected virtual void OnUrlAdded()
{
_listDirty = true;
ChildControlsCreated = false;
}
protected override void RenderContents(HtmlTextWriter writer)
{
if (_sharedUrls != null)
{
foreach (Pair p in _sharedUrls)
{
_list.Items.Add(new ListItem((string)p.First, (string)p.Second));
}
}
if (_userUrls != null)
{
foreach (Pair p in _userUrls)
{
_list.Items.Add(new ListItem((string)p.First, (string)p.Second));
}
}
base.RenderContents(writer);
}
public virtual bool IsDirty
{
get
{
return _listDirty;
}
}
public new virtual void Load(PersonalizationDictionary state)
{
if (state != null)
{
PersonalizationEntry sharedUrlsEntry = state["sharedUrls"];
if (sharedUrlsEntry != null)
{
_sharedUrls = (ArrayList)sharedUrlsEntry.Value;
}
PersonalizationEntry userUrlsEntry = state["userUrls"];
if (userUrlsEntry != null)
{
_userUrls = (ArrayList)userUrlsEntry.Value;
}
}
}
public virtual void Save(PersonalizationDictionary state)
{
if ((_sharedUrls != null) && (_sharedUrls.Count != 0))
{
state["sharedUrls"] = new PersonalizationEntry(_sharedUrls, PersonalizationScope.Shared);
}
if ((_userUrls != null) && (_userUrls.Count != 0))
{
state["userUrls"] = new PersonalizationEntry(_userUrls, PersonalizationScope.User);
}
}
}
}
开发者ID:.NET开发者,项目名称:System.Web.UI.WebControls.WebParts,代码行数:150,代码来源:IPersonalizable
注:本文中的System.Web.UI.WebControls.WebParts.IPersonalizable接口示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论