[DefaultProperty("Text")]
[ToolboxData("<{0}:CustomUserName runat=Server></{0}:CustomUserName>")]
public class CustomUserName:WebControl,IPostBackDataHandler
{
[Category("Appearance")]
[DefaultValue("")]
[Bindable(true)]
[Localizable(true)]
public string Text
{
get { return ViewState["Text"] != null ? (string)ViewState["Text"] : string.Empty; }
set { ViewState["Text"] = value; }
}
private static readonly object EventTextChanged = new object();
public event EventHandler TextChanged
{
add { Events.AddHandler(EventTextChanged, value);}
remove { Events.RemoveHandler(EventTextChanged,value);}
}
private void OnTextChanged(EventArgs eventArgs)
{
EventHandler textChangeHandler = Events[EventTextChanged] as EventHandler;
if (textChangeHandler != null)
{
textChangeHandler(this, eventArgs);
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string postValue = postCollection[postDataKey];
if (postValue != Text)
{
Text = postValue;
return true;
}
return false;
}
void IPostBackDataHandler.RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}
}
这个是自定义控件的问题
我在页面拖入一个自义控件
运行时可以触发LoadPostData
但当我拖入两个自定义控件(两个相同的自定义控件)时却不能触发LoadPostData
是不是UniqueID有问题
对不起,没有分啦