Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2005, 12:38 AM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 2
Thanked 1 Time in 1 Post
Default saving view state in dynamically created controls

Hi,
I am creating the controls on a web page dynamically, basically these are check boxes and user is supposed to check some of them and then go to next page. Also he can come back to the previous page on which I am showing the controls. The problem here is that when user comes back to the porevious page he all the dynamically created controls donot contain the view state. That is all the checkboxes created are unchecked. How I am doing all these is as follows.
1. I am getting the dats set in the Page_init event handler and calling a private methos which in turn is creating the controls.
2. In that method I am adding the control in this way.
chkAttribute = New CheckBox
chkAttribute.Text = viewDataset.Tables(0).Rows(intRowCount).ItemArray( 5)
chkAttribute.ID = "chkAttr" + viewDataset.Tables(0).Rows(intRowCount).ItemArray( 7).ToString()
                trResource = New TableRow
                tdResource = New TableCell
                tdAttribute = New TableCell
                tdResource.CssClass = "clsTableTemplate"
                'Checkbox is added for attribute
                tdAttribute.Controls.Add(chkAttribute)
                tdAttribute.CssClass = "clsTableTemplate"
                trResource.Cells.Add(tdResource)
                trResource.Cells.Add(tdAttribute)
                tblTemplateResources.Rows.Add(trResource)

tblTemplateResources is the ASP table I have created in design time.

Please help me in this regard. I am really struggling in this.

 
Old June 20th, 2005, 07:51 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Viewstate is intended for maintenance of the page state while you are viewing it. If you move to a different page you are no longer viewing it so viewstate is gone.

What you need to do is save the state of the checkboxes somewhere else to persist them across page visits. Usually this would be done thru a session value. You could create an array of values for the checkboxes and persist that to a session value. Then when you draw the checkbox list conditionally (Not IsPostBack) pull th values from the session value and set the checkbox check states accordingly.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me about dynamically created controls vingo_mail ASP.NET 2.0 Basics 1 March 24th, 2008 12:54 PM
Problems with Dynamically created controls Preeti_Singh .NET Framework 1.x 1 March 7th, 2007 01:30 PM
Saving Data to DB in dynamically created control ashokkumar ASP.NET 1.0 and 1.1 Basics 2 June 23rd, 2006 01:18 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.