开发者

Postback values missing after Viewstate moved to Database

Following advice from another post, 开发者_运维百科I have moved my viewstate to a database instead of disabling it entriely. However, now that I have done so, when I post back a form with a dropdown box in where the items have been added dynamically, the value is empty (this was happening when I disabled the viewstate and is the reason I moved it to the DB)

Why is this happening? It was Ok when the viewstate was on the page so why would it stop working now the Viewstate is in the database?

Using .NET 2.0

Thanks.


This is probably a life-cycle issue; you're probably not getting the ViewState back early enough, when the page expects it. Try loading the ViewState in the PageInit method and see if that fixes it?

Unless your ViewState is really large, I would keep it on the page. If you want to decrease page load times, start by adding a trace attribute to the page tag and see where any real bottle necks are (this will also give you the accurate ViewState size). Unless you're dealing with tens of thousands of records, the performance impact due to ViewState size should be acceptable.

UPDATE

Sample syntax for saving state of radio button selection:

protected override void LoadViewState(object savedState)
{
    base.LoadViewState(savedState);

    if (ViewState["SomeValue"] != null)
        someValue = stringViewState["SomeValue"];
}


protected override object SaveViewState()
{
    ViewState["SomeValue"] = someValue;

    return base.SaveViewState();
}   


I am not sure how you are implementing it but the way I did it was to create a custom PageStatePersister and PageAdapter. If you do it right, it just works. Here is an article that gives an example of how to do it with this method.

http://forums.asp.net/t/1293397.aspx/1?Store+ViewState+in+the+Database+instead+of+Hidden+Form+Field

Matthew

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜