According to "Developing Microsoft ASP.NET Server Controls and
Components", a control can get the LoadPostData event by using
RegisterRequiresPostBack, even if its UniqueID does not match that of
the Forms collection.
In the code below, I've tried doing this on a Page instead of a
regular control. However, it doesn't work. The LoadPostData is never
fired, even on postback. Does anyone have any idea why? How could I
make it work for a Page without having to put its UniqueID in the
Forms collection?
As an aside, the Page.ID remained null, even as late as OnPreRender
(that's why I assigned it in OnInit). Does anyone have any ideas
about this as well?
Thanks!!!
-Sam
public class Test : System.Web.UI.Page, IPostBackDataHandler
{
protected Button test;
override protected void OnInit(EventArgs e)
{
this.ID = "page";
test.Text = "Click Me!";
test.Click += new EventHandler(Test_Click);
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
Page.RegisterRequiresPostBack(this);
base.OnPreRender (e);
}
public void RaisePostDataChangedEvent()
{
}
public bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return false;
}
private void Test_Click(object sender, EventArgs e)
{
test.Text = "Clicked!";
}
}