raisepostbackevent not firing
I am building an ASP.NET custom server control. I have implemented both the IPostBackDataHandler and IPostBackEventHandler. OnPreRender I have registered the postback logic:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Page != null)
{
Page.RegisterRequiresRaiseEvent(this);
Page.RegisterRequiresPostBack(this);
}
}
The control uses a ImageButton开发者_运维百科 (but I have also tried with a simple Button); when it is clicked I can see the page "refreshes", and some data are posted (I checked that). However, I don't know why the RaisePostBackEvent(string eventArguments) is not firing.
Does anyone know what's going on? Could someone point me to the right direction to solve this?
Thanks in advance,
Cheers, Gianluca.
Registering your control during PreRender
phase is too late. You can do it during the Load
phase instead:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Page != null && Page.IsPostBack)
{
Page.RegisterRequiresRaiseEvent(this);
Page.RegisterRequiresPostBack(this);
}
}
精彩评论