473,881 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web: ViewState TableRowCollect ion.Remove

balabaster
797 Recognized Expert Contributor
Hi, I've been bashing my head against this since Friday and it's driving me nuts.

I've got an EntitySet(Of T) (LINQ) which is serialized to/from the viewstate by overriding the LoadViewState and SaveViewState methods. I've confirmed that this object is serialized/deserialized properly - so I know this bit is working as it should and when it should.

I have created a table template in which I have a header row which is just header text for the moment, and a footer row which contains an ImageButton to allow new rows to be added.

In the Page.Load event of my ascx I am building a TableRow for each of the LINQ Entities in my EntitySet, including an ImageButton to allow for the row to be deleted, the CommandArgument for each of the buttons corresponds to the id of the assigned row in my EntitySet. At this point the handler is added wired up and dumped into Cell 0 of the current row.

Now comes to deleting the rows using the dynamic buttons. When the event is fired, I remove the item from the EntitySet - of course, at this point, the table has been rebuilt from the original EntitySet (prior to the deletion having occurred).

So, having tried everything I can think of, I can't get the darn table row to delete. I can get all the rows to delete successfully if I start with the bottom row, deleting each row above in succession. The issue comes when I delete rows from the top down. The first row deletes successfully, but after that, rows aren't deleting properly. If I delete the first row, it removes, then I delete the second row and it removes the bottom one.

Page Load
Expand|Select|Wrap|Line Numbers
  1. Private Sub LoadPage(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3.         'Build table from grid
  4.         BuildTable(_Grid)
  5.  
  6.     End Sub
  7.  
  8. Protected Overrides Sub LoadViewState(ByVal savedState As Object)
  9.         Dim allStates As Object() = DirectCast(savedState, Object())
  10.         MyBase.LoadViewState(allStates(0))
  11.  
  12.         _Grid = _
  13.             LinqEntityUtil.Deserialize(Of RateGrid)( _
  14.                 DirectCast(allStates(1), String) _
  15.             )
  16.  
  17.         _Context = _
  18.             LinqEntityUtil.Deserialize(Of RatingsDataContext)( _
  19.                 DirectCast(allStates(2), String) _
  20.             )
  21.  
  22.     End Sub
  23.  
  24.     Protected Overrides Function SaveViewState() As Object
  25.  
  26.         Dim baseState = MyBase.SaveViewState()
  27.         Dim allStates(2) As Object
  28.  
  29.         allStates(0) = baseState
  30.  
  31.         allStates(1) = _
  32.             LinqEntityUtil.Serialize(Of RateGrid)(_Grid)
  33.  
  34.         allStates(2) = _
  35.             LinqEntityUtil.Serialize(Of RatingsDataContext)(_Context)
  36.  
  37.         Return allStates
  38.  
  39.     End Function
  40.  
  41.     Private Sub DeleteRow(ByVal Sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
  42.  
  43.         Dim ThisRow = DirectCast(Sender.Parent.Parent, TableRow)
  44.  
  45.         Dim RowToDelete = _Grid.RateGridRows.Where( _
  46.                               Function(r) r.RowGuid.ToString = e.CommandArgs _
  47.                           ).Single
  48.  
  49.         'Add RowToDelete to collection to delete from table
  50.         'in the PreRender
  51.  
  52.         RateGridTable.Rows.Remove(ThisRow)
  53.         _Grid.RateGridRows.Remove(RowToDelete)
  54.  
  55.     End Sub
Can anyone shed any light on what's going wrong? Am I wiring things up in the wrong stages of the page lifecycle? I've tried adding the TableRows to be deleted to a collection of rows to be removed in the Page.PreRender event. It seems as though when the row is deleted and the table is reloaded from the ViewState on the next postback the ImageButton instances in the ViewState aren't recognizing that rows (and consequently controls) have been deleted from the table.
Oct 28 '08 #1
1 1833
balabaster
797 Recognized Expert Contributor
So I got around it in the end by remodelling my code slightly so that the table is completely built dynamically instead of adding rows to an initial ASCX template table. I don't like the fact that I have to build the table completely in the page load and then again at the end of the delete row event - it seems to me that this is a needless waste of resources, but needs must.

I would love to hear if someone has managed to get similar functionality working without having to reload the whole table twice - I'd just like to delete the offending row from the table in the delete row event, but I can't for the life of me get it to work properly.
Oct 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1832
by: Chris Thompson | last post by:
I have a page that uses a custom object I wrote to build a table. I also have a post back to the page to remove items from that table. When the page loads I can see the viewstate code on the source of the page is about 5 lines. When I post back to remove an item and rebuild the page it works. I view the source of the page and the viewstate code has doubled in size even though I have less data for it to hold. On the second post back I...
2
2556
by: dan | last post by:
I have created a class called BasePage that inherits from System.Web.UI.Page so that I can implement a "template" for all pages in an app. My BasePage class is in a class library project and there is also a web app in the same solution that has a project reference back to the class library. When I create a new web form in VS.NET, I simply change the code behind class to inherit from BasePage instead of System.Web.UI.Page.
0
1382
by: Dan | last post by:
I posted a similar post regarding problems with VS.NET design mode. I fixed that problem (with much thanks to this newsgroup) but now I have a second problem. I have created a class called BasePage that inherits from System.Web.UI.Page so that I can implement a "template" for all pages in an app. My BasePage class is in a class library project and there is also a web app in the same solution that has a project reference back to the...
6
1334
by: Patrick.O.Ige | last post by:
I'm constructing a link from a viewstate and passing it on to a querystring.. After clciking a checkboxlist i add the value to a viewstate and return it but on the same page i also have a dropdwonlist whcih also does similar. But i noticed that after selecting a checkBox and it appends the value tot he Querystring and then i select a dropdownlist.. The Viewstate onluy returns the dropdownlist value and the checkboxlist is gone.. Is there...
16
3771
by: Rob Meade | last post by:
Hi all, I am just making a few methods in my base class, one of which returns a horizontal line, formatted on the page as *I* want it..its basically a collection of three table rows. I discovered the TableRowCollection this evening, so I was hoping that I could return one of these objects with my three rows inside it, and then assign the collection to the table...something like...
7
2155
by: GS | last post by:
Hello, I'm receiving The state information is invalid for this page and might be corrupted error message when running code below. This happens on second post back. Why is it happening? My webpage contains 2 dropdowns controls and I save information entered by user in ViewState variable containing array ArrayList MyCoordinates = (ArrayList) ViewState ; if (MyCoordinates == null) { MyCoordinates = new ArrayList ();
0
1727
by: Jeremy Chapman | last post by:
I am thinking of implementing System.Web.UI.SessionPageStatePersister as a method of storing viewstate in the session. Before I do, I am browsing threw the class's code using reflector just to get an understanding of performance/memory hits on the server. I've attached the code below, and my understanding of it is less that what I like. Is there anyone here with a more familiar knowledge of how it works? I'm wondering how it cleans up...
6
1904
by: sri_san | last post by:
Hello, I have a aspx page in which I would like to eliminate all of the hidden variables as this page would be imported to an email client and the hidden controls are usually rendered in the mail client. The asp.net form does have the form input hidden control inspite the viewstate is disabled at the page level. Isnt there a way to eliminate it? And, as per my understanding, it just cant be eliminated. Now, I was trying to parse the page...
0
2236
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with dynamic controls. Our application was having a problem very similar to the one described here: http://weblogs.asp.net/alessandro/archive/2008/01/04/failed-to-load-viewstate-typical-problem-with-an-obvious-solution.aspx Unfortunately, the "fix"...
0
9926
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
9775
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
11094
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
10715
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...
1
10811
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10396
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...
1
7952
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
4194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3221
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.