开发者

raisepostbackevent not firing

开发者 https://www.devze.com 2023-01-16 19:19 出处:网络
I am building an ASP.NET custom server control. I have implemented both the IPostBackDataHandler and IPostBackEventHandler.

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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消