PC Review


Reply
Thread Tools Rate Thread

Dynamic Ajax Controls and Postback

 
 
Peter
Guest
Posts: n/a
 
      5th Mar 2008
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


 
Reply With Quote
 
 
 
 
cfps.Christian
Guest
Posts: n/a
 
      5th Mar 2008
I don't remember having that problem when I was trying to add date
items to my form but what I did to make it easy is I created a User
Control and called it like DateTimePicker and dynamically added that
to the form so I didn't have to set all the properties.

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      5th Mar 2008
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
>
>
>

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      9th Mar 2008
Thank You

Creating User Control solved the problem and works a lot better with User
Control

"cfps.Christian" <(E-Mail Removed)> wrote in message
news:c40173b5-ccd8-41bb-bda2-(E-Mail Removed)...
>I don't remember having that problem when I was trying to add date
> items to my form but what I did to make it easy is I created a User
> Control and called it like DateTimePicker and dynamically added that
> to the form so I didn't have to set all the properties.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How get past invalid postback when using AJAX ScriptManager and UpdatePanel controls? Ronald S. Cook Microsoft ASP .NET 0 23rd Jan 2008 07:33 PM
dynamic controls + ajax Gui Microsoft ASP .NET 5 14th Jun 2007 06:15 PM
Re: dynamic controls + ajax Yuriy Solodkyy Microsoft ASP .NET 0 14th Jun 2007 01:25 PM
dynamic controls + ajax Gui Microsoft C# .NET 0 13th Jun 2007 03:26 PM
Dynamic Controls and Postback Steve Roszko Microsoft ASP .NET 2 21st Oct 2003 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:12 PM.