开发者

save Load User Control Dynamic to viewstate

开发者 https://www.devze.com 2022-12-15 23:17 出处:网络
i add user control dynamcly to the page and trying to save to viewstate when i triyed to save the placeholder to the view state i got this error

i add user control dynamcly to the page and trying to save to viewstate when i triyed to save the placeholder to the view state i got this error " PlaceHolder is not mark as serializabl开发者_如何学Ce."

here is my code

  Controls_PriceControl ctrl = (Controls_PriceControl)LoadControl("../Controls/PriceControl.ascx");
    plcPrices.Controls.Add(ctrl);

    ViewState["plcPrices"] = plcPrices;

can you assiset me with this issue ?

thanks !


You shouldn't save your actual controls to the ViewState, but only th their state (usually the properties). Saving and loading control properties can often be done directly in the property declaration:

public class FooControl : Control
{
    public string Bar
    {
        get { return ViewState["Bar"] as string; }
        set { return ViewState["Bar"] = value; }
    }
}
0

精彩评论

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