View State Null In IPostBackHandler

Discussion in 'ASP .Net Building Controls' started by Mark, Jun 8, 2007.

  1. Mark

    Mark Guest

    Hi,

    I had a datetimepicker server control that worked great in 1.x but I am
    having trouble with it in ASP.NET 2.x For some reason, the ViewState value
    is always null on postback so IPostBackDataHandler.LoadPostData is unable to
    access the properties correctly. Is there a change I should make? Here's
    the iPostBackHandler code:

    void IPostBackDataHandler.RaisePostDataChangedEvent() {
    //OnSelectedIndexChanged(System.EventArgs.Empty);
    OnDateChanged(System.EventArgs.Empty);
    }

    bool IPostBackDataHandler.LoadPostData(string postDataKey,
    System.Collections.Specialized.NameValueCollection postCollection) {

    // when it access the SelectedDate here, its ViewState value is null

    DateTime PreviousSelectedDate = SelectedDate;
    DateTime DateSubmitted = SelectedDate;

    // other code

    }

    The code for the SelectedDate property is

    [
    Description("Gets or sets the date for the DateTimePicker control."),
    Category("Appearance"),
    //DefaultValue(),
    Bindable(true),
    ]
    public virtual DateTime SelectedDate
    {
    get
    {
    object savedSelectedDate;

    savedSelectedDate = this.ViewState["SelectedDate"];
    if (savedSelectedDate != null)
    return (DateTime) savedSelectedDate;
    return DateTimeNotSet;
    }
    set
    {
    this.ViewState["SelectedDate"] = value;
    }

    }


    I've checked and EnabledViewState is not set to false on the page or
    controls. Any suggestions?
     
    Mark, Jun 8, 2007
    #1
    1. Advertisements

  2. Hi Mark,

    I'm not aware of the IPostbackDataHandler has changed much in 2.0.

    I also tried the code examples of book "Developing Microsoft? ASP.NET
    Server Controls and Components" here
    http://www.microsoft.com/mspress/books/companion/5728.aspx which was
    previously built with VS2002. The SimpleTextBox which demonstrates
    IPostBackDataHandler works fine in VS2005.

    Please post more of your control's code to see if it's related to its
    implementation. Thanks.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 11, 2007
    #2
    1. Advertisements

  3. Mark

    Mark Guest

    Hi Walter,

    Thank you for your response! You are correct that IPostBackHandler wasn't
    changed in ASP.NET 2.0. After looking at this more I found that the problem
    was caused by a deep bug somewhere else. I am sorry for the inconvenience
    and thank you for your help!
     
    Mark, Jun 11, 2007
    #3
  4. Hi Mark,

    You're welcome. I'm glad to know that you've solved the issue.

    Have a nice day!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 12, 2007
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.