at postback you need to create the controls in OnInit, so they exist when the
loadviewstate is called. you need to be carefull of creating autonamed
controls, becuase if you do it in the wrong order on postback, the names
change.
-- bruce (sqlwork.com)
"Peter" wrote:
> I am adding web controls dynamically and everything works fine until I've
> tried to add CalendarExtender from ASP.NET Ajax library. The
> CalanderExtender gets added and works fine until I submit the form and then
> I get the following error:
>
> Microsoft JScript runtime error:
> Sys.WebForms.PageRequestManagerServerErrorException: Failed to load
> viewstate. The control tree into which viewstate is
> being loaded must match the control tree that was used to save viewstate
> during the previous request. For example, when adding controls dynamically,
> the controls added during a post-back must match the type and position of
> the controls added during the initial request.
>
> This error occurs before the Page_Load event.
>
> Does anyone know how to fix this?
>
>
> Here's how I am adding the Calendar Extender
>
> txt = new TextBox();
> txt.MaxLength = parm.MaxLength;
> txt.ID = parm.ParameterNameID;
> txt.Text = "";
> txt.EnableViewState = true;
> txt.AutoPostBack = false;
> lbl.AssociatedControlID = txt.ID;
> this.PlaceHolder1.Controls.Add(txt);
>
> CalendarExtender ce = new CalendarExtender();
> ce.ID = parm.ParameterNameID + "_CalendarExtender";
> ce.TargetControlID = parm.ParameterNameID;
> ce.Format = "d";
> ce.EnableViewState = true;
> this.PlaceHolder1.Controls.Add(ce);
>
>
>
> Thank You
>
>
>
> Peter
>
>
>
|