View State Null In IPostBackHandler

M

Mark

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?
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
M

Mark

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!
 
W

Walter Wang [MSFT]

Hi Mark,

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

Have a nice day!

Regards,
Walter Wang ([email protected], 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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top