473,750 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling view state with Dynamic controls

1) I build a Html Table dynamically (Header Row, and then 2 rows with data
All 2 rows have 2 cells: cell(0) contains a delete button (ASP Button),
cell(1) contains a HTML Text box
2) On Form Load and get some data from a dataset and then from it's contents
build the page

At this point the page is rendered and 2 rows are displayed. There is an Add
button that a user can click to add another row to the table. This works fine
and the row is added.

Now if the user clicks the delete button in row 2 the form is posted back, I
rebuild the page, and then in the click event for the delete button remove
the row from the table and the dataset. All appears to be fine at this point.

Now if the user clicks the add button again another row is added, but this
time row 2's textbox has the wrong value. It appears to be related to the
view state. I think the view state somehow is not getting cleared when the
row is removed.

Any help would be appreciated

Jan 16 '06 #1
3 1720
Are you setting the value in the view state after deleting the row?

--
Kurt Farrar
..NET Developer & Computer Enthusiast

"gaDev" wrote:
1) I build a Html Table dynamically (Header Row, and then 2 rows with data
All 2 rows have 2 cells: cell(0) contains a delete button (ASP Button),
cell(1) contains a HTML Text box
2) On Form Load and get some data from a dataset and then from it's contents
build the page

At this point the page is rendered and 2 rows are displayed. There is an Add
button that a user can click to add another row to the table. This works fine
and the row is added.

Now if the user clicks the delete button in row 2 the form is posted back, I
rebuild the page, and then in the click event for the delete button remove
the row from the table and the dataset. All appears to be fine at this point.

Now if the user clicks the add button again another row is added, but this
time row 2's textbox has the wrong value. It appears to be related to the
view state. I think the view state somehow is not getting cleared when the
row is removed.

Any help would be appreciated

Jan 16 '06 #2
I'm not sure what you mean. When the user clicks the delete row button:
1) postback to the page
2) rebuild the page(including the row that was deleted
3) delete the row from the table
4) update the dataset from which I deleted the table
5) Update the contents of the table

As of now, all of the above is done during form load.

Thanks for help!

"Kurt Farrar" wrote:
Are you setting the value in the view state after deleting the row?

--
Kurt Farrar
.NET Developer & Computer Enthusiast

"gaDev" wrote:
1) I build a Html Table dynamically (Header Row, and then 2 rows with data
All 2 rows have 2 cells: cell(0) contains a delete button (ASP Button),
cell(1) contains a HTML Text box
2) On Form Load and get some data from a dataset and then from it's contents
build the page

At this point the page is rendered and 2 rows are displayed. There is an Add
button that a user can click to add another row to the table. This works fine
and the row is added.

Now if the user clicks the delete button in row 2 the form is posted back, I
rebuild the page, and then in the click event for the delete button remove
the row from the table and the dataset. All appears to be fine at this point.

Now if the user clicks the add button again another row is added, but this
time row 2's textbox has the wrong value. It appears to be related to the
view state. I think the view state somehow is not getting cleared when the
row is removed.

Any help would be appreciated

Jan 17 '06 #3
Shouldn't your code to delete the row from your dataset be in the
DeleteButton_Cl icked event?

My way of doing it would be (pseudo code):

sub page_load
if not(ispostback( )) then
createdataset 'create dataset from datasource
savedataset 'put a copy of the dataset into the view state
else
loaddataset 'reload the dataset from the viewstate
end if
end sub

sub addButton_Click ed
addRow 'add row to dataset
savedataset 'update the viewstate with the updated dataset
end sub

sub deleteButton_Cl icked
delRow 'remove the row from the dataset
savedataset 'update the viewstate with the updated dataset
end sub

Hope this helps.

--
Kurt Farrar
..NET Developer & Computer Enthusiast

"gaDev" wrote:
I'm not sure what you mean. When the user clicks the delete row button:
1) postback to the page
2) rebuild the page(including the row that was deleted
3) delete the row from the table
4) update the dataset from which I deleted the table
5) Update the contents of the table

As of now, all of the above is done during form load.

Thanks for help!

"Kurt Farrar" wrote:
Are you setting the value in the view state after deleting the row?

--
Kurt Farrar
.NET Developer & Computer Enthusiast

"gaDev" wrote:
1) I build a Html Table dynamically (Header Row, and then 2 rows with data
All 2 rows have 2 cells: cell(0) contains a delete button (ASP Button),
cell(1) contains a HTML Text box
2) On Form Load and get some data from a dataset and then from it's contents
build the page

At this point the page is rendered and 2 rows are displayed. There is an Add
button that a user can click to add another row to the table. This works fine
and the row is added.

Now if the user clicks the delete button in row 2 the form is posted back, I
rebuild the page, and then in the click event for the delete button remove
the row from the table and the dataset. All appears to be fine at this point.

Now if the user clicks the add button again another row is added, but this
time row 2's textbox has the wrong value. It appears to be related to the
view state. I think the view state somehow is not getting cleared when the
row is removed.

Any help would be appreciated

Jan 17 '06 #4

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

Similar topics

3
1586
by: Bren | last post by:
I am developing a web based app. in .net, with C# as the code behind.the problem I am having is with view state for a page. the page is capturing an event fired in an object. the event changes the properties of various controls in the UI. the event is fired when the user enters some info. on the page, initiating a post back etc. However, when i test the page, the changes that should appear in the UI don't happen. debugging through the code...
1
1489
by: Sunil Menon | last post by:
Dear All, We all always have a problem dynamic controls and ViewState...Suppose we want to create dynamic Controls on Load of the page and Save its value in the ViewState and get them back, will it be asking for too much...I guess no...:-) I have found a solution that I want to share in this newsgroup... 1. Write a page Class 'basePage.cs'. 2. In this page class write two functions : SaveCtrlViewState(id, val) { ViewState = val }...
0
1103
by: Bren | last post by:
I am developing a web based app. in .net, with C# as the code behind.the problem I am having is with view state for a page. the page is capturing an event fired in an object. the event changes the properties of various controls in the UI. the event is fired when the user enters some info. on the page, initiating a post back etc. However, when i test the page, the changes that should appear in the UI don't happen. debugging through the code...
1
1235
by: Adrijan Josic | last post by:
I have a bunch of user controls that contain TextBoxes, Repeaters and so on. Some of the user controls even contain other user controls. The user controls also usually have some of their properties saved in viewstate. What I need is: if a user control is not visible it shouldn't save it's viewstate or the viewstate of the user controls and server controls it contains and so on recursively. Im guessing I should override the SaveViewState...
4
1582
by: Pham Nguyen | last post by:
I have two maybe related questions about view state and the life cycle of controls: 1) When does the view state in a control get restored? I thought there was a LoadViewState event that occured before the Load event when the view state got restored. However, I have a custom control that dynamically adds a Label control inside of its OnLoad() method. The Label still maintains its state across requests -- if the Label is added in the...
2
783
by: Brad | last post by:
I have an intranet app that has just started sporadically getting the following error "The viewstate is invalid for this page and might be corrupted." By sproadic I mean 3-4 times during the past two days out of 100's of hits. The error just started yesterday and this app has been running for quite some time without this error and has not been updated just before or after the error started. Reseaching this error I've checked the...
4
4383
by: Souri Challa | last post by:
Hello All, When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the DataGridItem(e.Item.DataItem is null) in the event arguments has no values. Is there any way to access and manipulate the row contents in this case ? Thanks in advance for any insigts in to this. -Souri
1
1361
by: Paul Johnson | last post by:
I have problems with eventhandlers when dynamically moving controls in ASP.NET. The controls are loaded into a placeholder on postback so that the eventhadlers can fire. If a move evet or delete event fires the place holder is cleared and repopulated. Unfortunatly the UniqueID carries on increaseing from the last UniqueID of the cleared controls. This meens if a button is clicked and page is posted when the page is rebuild the...
3
2783
by: jclark0731 | last post by:
I am trying to redirect to the same page after a post-back is fired to ensure that the post-back never makes it into history (avoids the post-back/refresh problem). While doing this, I wish to maintain the view state of the page (page contains dynamic controls as well). Has anybody done this before? I assume that I need to store the viewstate info in session (as the 64-bit encoded string or as the statebag? using sql server session...
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8264
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.