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?

    --
    Sincerely,

    Mark Fox
     
    Mark, Jun 8, 2007
    #1
    1. Advertising

  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. Advertising

  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!

    --
    Sincerely,

    Mark Fox


    "Walter Wang [MSFT]" wrote:

    > 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.
    >
    >
     
    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. 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. VB Programmer
    Replies:
    1
    Views:
    605
    VB Programmer
    Jul 10, 2003
  2. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Icon View and list View in ASP.NET

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Mar 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    511
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Mar 7, 2005
  3. Luqman
    Replies:
    2
    Views:
    3,825
    Luqman
    Feb 1, 2006
  4. Replies:
    5
    Views:
    26,709
    Mike Schilling
    Mar 29, 2006
  5. Parthiv Joshi
    Replies:
    1
    Views:
    709
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page