首页 新闻 赞助 找找看

自定义控件 UniqueID

0
[已关闭问题]

 

代码
[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有问题

对不起,没有分啦

湖的主页 | 初学一级 | 园豆:0
提问于:2010-04-02 11:17
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册