IPostBackEventHandler

Discussion in 'ASP .Net Building Controls' started by ggeshev, Mar 21, 2008.

  1. ggeshev

    ggeshev Guest

    Hello!

    I am building a Webcontrol.

    public class MyCustomControl : WebControl, IPostBackEventHandler,
    IPostBackDataHandler {
    .......

    void IPostBackEventHandler.RaisePostBackEvent(string args)
    {
    RaisePostBackEvent(args);
    }

    protected virtual void RaisePostBackEvent(string args) {

    }


    bool IPostBackDataHandler.LoadPostData(string postDataKey,
    NameValueCollection values)
    {
    return LoadPostData(postDataKey, values);
    }

    protected virtual bool LoadPostData(string postDataKey,
    NameValueCollection values)
    {
    return true;
    }

    void IPostBackDataHandler.RaisePostDataChangedEvent()
    {
    RaisePostDataChangedEvent();
    }

    protected virtual void RaisePostDataChangedEvent()
    {

    }

    }


    The problem is - Nevertheless I implement IPostBackEventHandlerand
    IPostBackDataHandler , methods RaisePostBackEvent, LoadPostData and
    RaisePostDataChangedEvent are never called.

    Why is so?
     
    ggeshev, Mar 21, 2008
    #1
    1. Advertising

  2. ggeshev

    Tony Guest

    I think IPostBackEventHandler only work when you implement in Page control.

    "ggeshev" <> wrote in message
    news:%...
    > Hello!
    >
    > I am building a Webcontrol.
    >
    > public class MyCustomControl : WebControl, IPostBackEventHandler,
    > IPostBackDataHandler {
    > .......
    >
    > void IPostBackEventHandler.RaisePostBackEvent(string args)
    > {
    > RaisePostBackEvent(args);
    > }
    >
    > protected virtual void RaisePostBackEvent(string args) {
    >
    > }
    >
    >
    > bool IPostBackDataHandler.LoadPostData(string postDataKey,
    > NameValueCollection values)
    > {
    > return LoadPostData(postDataKey, values);
    > }
    >
    > protected virtual bool LoadPostData(string postDataKey,
    > NameValueCollection values)
    > {
    > return true;
    > }
    >
    > void IPostBackDataHandler.RaisePostDataChangedEvent()
    > {
    > RaisePostDataChangedEvent();
    > }
    >
    > protected virtual void RaisePostDataChangedEvent()
    > {
    >
    > }
    >
    > }
    >
    >
    > The problem is - Nevertheless I implement IPostBackEventHandlerand
    > IPostBackDataHandler , methods RaisePostBackEvent, LoadPostData and
    > RaisePostDataChangedEvent are never called.
    >
    > Why is so?
    >
     
    Tony, Mar 26, 2008
    #2
    1. Advertising

  3. On Mar 21, 1:32 pm, "ggeshev" <> wrote:
    > Hello!
    >
    > I am building a Webcontrol.
    >
    > public class MyCustomControl : WebControl, IPostBackEventHandler,
    > IPostBackDataHandler {
    > .......
    >
    > void IPostBackEventHandler.RaisePostBackEvent(string args)
    > {
    > RaisePostBackEvent(args);
    > }
    >
    > protected virtual void RaisePostBackEvent(string args) {
    >
    > }
    >
    > bool IPostBackDataHandler.LoadPostData(string postDataKey,
    > NameValueCollection values)
    > {
    > return LoadPostData(postDataKey, values);
    > }
    >
    > protected virtual bool LoadPostData(string postDataKey,
    > NameValueCollection values)
    > {
    > return true;
    > }
    >
    > void IPostBackDataHandler.RaisePostDataChangedEvent()
    > {
    > RaisePostDataChangedEvent();
    > }
    >
    > protected virtual void RaisePostDataChangedEvent()
    > {
    >
    > }
    >
    > }
    >
    > The problem is - Nevertheless I implement IPostBackEventHandlerand
    > IPostBackDataHandler , methods RaisePostBackEvent, LoadPostData and
    > RaisePostDataChangedEvent are never called.
    >
    > Why is so?


    Just implementing IPostBackDataHandler does nothing. You have to
    register the control with the page. I usually do it in PreRender,
    because if a page doesn't get rendered it can't handle post back
    data. I don't think it really matters though. I think the same
    applies to IPostBackEventHandler but I have never used that.

    protected void Page_PreRender(object sender,
    EventArgs e)
    {
    this.Page.RegisterRequiresPostBack(this);
    }
     
    Brian Hartsock, Apr 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2xvbSBEYXJr?=

    Table of dynamic buttons implemeting IPostBackEventHandler

    =?Utf-8?B?S2xvbSBEYXJr?=, Jun 17, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    690
    avnrao
    Jun 17, 2004
  2. Sam Martin
    Replies:
    4
    Views:
    7,700
    William F. Robertson, Jr.
    Sep 15, 2004
  3. Mike
    Replies:
    11
    Views:
    4,136
    =?Utf-8?B?aGFuIHpoaXlhbmc=?=
    Sep 22, 2005
  4. Mr Newbie
    Replies:
    1
    Views:
    3,628
    Mr Newbie
    Nov 7, 2005
  5. Louis Somers
    Replies:
    3
    Views:
    3,280
    RichardPetheram
    Oct 17, 2008
Loading...

Share This Page