Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Dynamic Ajax Controls and Postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 05 Mar 2008 20:03 GMT
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
cfps.Christian - 05 Mar 2008 21:00 GMT
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.
Peter - 09 Mar 2008 06:52 GMT
Thank You

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

>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.
bruce barker - 05 Mar 2008 23:24 GMT
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)

> I am adding web controls dynamically and everything works fine until I've
> tried to add CalendarExtender from ASP.NET Ajax library.  The
[quoted text clipped - 34 lines]
>
> Peter

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.