本文整理汇总了C#中System.Web.UI.WebControls.WebParts.ITrackingPersonalizable接口的典型用法代码示例。如果您正苦于以下问题:C# ITrackingPersonalizable接口的具体用法?C# ITrackingPersonalizable怎么用?C# ITrackingPersonalizable使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
ITrackingPersonalizable接口属于System.Web.UI.WebControls.WebParts命名空间,在下文中一共展示了ITrackingPersonalizable接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: return
namespace PersTest
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
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;
public override string Subtitle
{
get
{
return Text;
}
}
[Personalizable, WebBrowsable]
public virtual string Text
{
get
{
object o = ViewState["Text"];
return (o != null) ? (String)o : "My Links";
}
set
{
ViewState["Text"] = value;
}
}
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);
}
}
}
public class UrlListExWebPart : UrlListWebPart, ITrackingPersonalizable
{
private string _trackingLog = String.Empty;
private bool _loading;
private bool _saving;
public override string Text
{
get
{
return base.Text;
}
set
{
if (base.Text.Equals(value) == false)
{
base.Text = value;
SetPersonalizationDirty();
}
}
}
protected override void OnUrlAdded()
{
base.OnUrlAdded();
SetPersonalizationDirty();
}
protected override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
writer.Write("<br />");
writer.Write("<pre id=\"" + ClientID + "$log" + "\">");
writer.Write(_trackingLog);
writer.Write("</pre>");
}
public override void Load(PersonalizationDictionary state)
{
if (_loading == false)
{
throw new InvalidOperationException();
}
}
public override void Save(PersonalizationDictionary state)
{
if (_saving == false)
{
throw new InvalidOperationException();
}
base.Save(state);
}
bool ITrackingPersonalizable.TracksChanges
{
get
{
return true;
}
}
void ITrackingPersonalizable.BeginLoad()
{
_loading = true;
_trackingLog = "1. BeginLoad\r\n";
}
void ITrackingPersonalizable.BeginSave()
{
_saving = true;
_trackingLog += "3. BeginSave\r\n";
}
void ITrackingPersonalizable.EndLoad()
{
_loading = false;
_trackingLog += "2. EndLoad\r\n";
}
void ITrackingPersonalizable.EndSave()
{
_saving = false;
_trackingLog += "4. EndSave";
}
}
}