473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP. Net gurus? Problem with ViewState

Hi,
I am using ASP.NET 2.0 with C#. ViewState is not working for controls
created at runtime.
On a page I have a few (static) textboxes that get populated from database
and then I create other textboxes during runtime using the folloiwng steps:
1. I add a TableRow(TR) to an existing table using HtmlTableRow
2. I add TableCells(TD) to the above TR using HtmlTableCell
3. I add TextBoxes to the TDs using using TextBox

Then I start entering into the runtime Textboxes, when done, I press Enter
which does a postback. Now I am back at the page and my first list of static
textboxes are still there while the runtime textboxes and the TR and TDs are
gone. If I try to recreate the TRs with the same name as before, I get an
invalid ID meaning that the TR is still on the form. I just don't see it.

How would I presere the runtime web controls upon postback? How would I see
them?

Thanks

Oct 30 '06 #1
2 1062
make sure you call those creations again in the postback section or they won't be created
"Merdaad" <Me*****@discussions.microsoft.comwrote in message news:1B**********************************@microsof t.com...
Hi,
I am using ASP.NET 2.0 with C#. ViewState is not working for controls
created at runtime.
On a page I have a few (static) textboxes that get populated from database
and then I create other textboxes during runtime using the folloiwng steps:
1. I add a TableRow(TR) to an existing table using HtmlTableRow
2. I add TableCells(TD) to the above TR using HtmlTableCell
3. I add TextBoxes to the TDs using using TextBox

Then I start entering into the runtime Textboxes, when done, I press Enter
which does a postback. Now I am back at the page and my first list of static
textboxes are still there while the runtime textboxes and the TR and TDs are
gone. If I try to recreate the TRs with the same name as before, I get an
invalid ID meaning that the TR is still on the form. I just don't see it.

How would I presere the runtime web controls upon postback? How would I see
them?

Thanks

Oct 31 '06 #2
Hi,

Merdaad wrote:
How would I presere the runtime web controls upon postback? How would I see
them?
controls that you add during a page's runtime won't "survive" a postback.
That is, you'll have to recreate them every time.
I guess that you create your controls in the Page_Load-event, but within a
<if (!Page.IsPostBack) {...}>-block. Move the creation of your
runtime-controls out of that block so they're called everytime the page is
being created and sent.

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Oct 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: S.Sigal | last post by:
Hello: I've been trying to 'organize' the layout of my larger controls by moving variables into instances of subclasses...but it just dawned on me that I might be opening a real can of worms due...
1
by: John Cosmas | last post by:
I've got a page which loads up a different user control into a placeholder control every time a button is clicked on the parent page. I use a statement like...
2
by: Ryan Ternier | last post by:
I'm playing around with Cache and Viewstate. I've made a small little example that reminds me of grade 12: if(!IsPostBack) { ArrayList alTest = new ArrayList(); alTest.Add("This is from...
0
by: Mike Hofer | last post by:
Hi everyone. I could really use some help. First, the backstory: ===================== I *really* need a 3-state checkbox for my ASP.NET application. Specifically, I need one that lets me set...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
6
by: mosscliffe | last post by:
I am testing for how/when a page is posted back and I decided to use a ViewState variable in PageLoad to set up a counter, but it appears, the ViewState is cleared on each PageLoad. So then I used...
6
by: paul.hester | last post by:
Hi all, Does anyone know why the ViewState would be empty? When I'm receiving a postback, I can access a posted value using controlName.Value but not ViewState. I have EnableViewState set...
2
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.