473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview viewstate failed to load error with too many rows!

1 New Member
Hi,

I am quite desperate now because I made a nice webshop with a gridview where the customer is able to update the amount of products (Hostas in my situation) or delete the row.
The problem is that every works really fine with this code when customers order approximatelly a maximum of 35 products.
What I learned so far is to set the EnableViewState ="False" for all the labels that don't need a viewstate. This helped a lot.

What can I do to make this work for an unlimited order?

You help is very appreciated!!!! !

This is my code so far:
Expand|Select|Wrap|Line Numbers
  1. <asp:AccessDataSource id="AccessDataSource1" Runat="Server"
  2.     DataFile="<%$ connectionStrings: AccessHostaConnection %>"
  3.   OnSelected="Get_Rows"
  4.  
  5.   SelectCommand="SELECT * FROM ShopCart WHERE OrderNumber=@OrderNumber order by naam"
  6.  
  7.   UpdateCommand="UPDATE ShopCart SET Aantal=@Aantal
  8.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  9.  
  10.   DeleteCommand="DELETE FROM ShopCart
  11.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  12. >
  13.   <SelectParameters>
  14.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  15.     PropertyName="Text"/>
  16.   </SelectParameters>
  17.   <UpdateParameters>
  18.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  19.     PropertyName="Text"/>
  20.   </UpdateParameters>
  21.   <DeleteParameters>
  22.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  23.     PropertyName="Text"/>
  24.   </DeleteParameters>
  25.  
  26. </asp:AccessDataSource>
  27.  
  28. <asp:Label ID="Label1" Text="Hosta Shopcart" Font-Size="14pt" ForeColor="#8E001C" 
  29. Runat="Server"/> &nbsp;   <asp:hyperlink id="Catalogus" Text="Continue shopping" navigateUrl="nwcatalog2.aspx" runat="server"> </asp:hyperlink> 
  30.             <asp:Label ID="voorraad" runat="server" ></asp:Label>
  31.             <asp:Label ID="logtekstlabel" runat="server"></asp:Label>
  32. <table border="0">
  33. <tr>
  34.   <td><b>Order number: </b></td>
  35.   <td><asp:Label id="OrderNumberLabel" Runat="Server"/></td>
  36. </tr>
  37. </table>
  38. <table>
  39. <tr>
  40. <td>
  41.             <b>You can change the amount of Hostas by means of the &quot;Change&quot;-button per 
  42.             Hosta. Subsequently you can change the amount you wish to order and finally you 
  43.             need to confirm your change by the &quot;Update&quot;-button.</td>            
  44.  
  45. </tr>
  46. </table>
  47.  
  48. <asp:Label id="NoItemsMessage" Runat="Server"
  49.   Text="No Hostas in Shopcart" EnableViewState="False" Visible="False"
  50.   Width="206px" Height="1px" BackColor="#E0E0E0" ForeColor="#8E001C"
  51.   BorderStyle="Solid" BorderWidth="1px" BorderColor="Silver" 
  52.   Style="margin-top:10px; padding:15px"/>
  53.  
  54. <asp:Panel ID="Panel1" Width="700" Runat="Server"
  55. ForeColor="#990000" HorizontalAlign="Left">
  56.   <asp:Label id="ErrMessage" Text=" " EnableViewState="False" Runat="Server"/>
  57. </asp:Panel>
  58.  
  59. <asp:AccessDataSource id="ShopCartSource" Runat="Server"
  60.     DataFile="<%$ connectionStrings: AccessHostaConnection %>"
  61.   OnSelected="Get_Rows"
  62.  
  63.   SelectCommand="SELECT * FROM ShopCart WHERE OrderNumber=@OrderNumber order by naam"
  64.  
  65.   UpdateCommand="UPDATE ShopCart SET Aantal=@Aantal
  66.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  67.  
  68.   DeleteCommand="DELETE FROM ShopCart
  69.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  70. >
  71.   <SelectParameters>
  72.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  73.     PropertyName="Text"/>
  74.   </SelectParameters>
  75.   <UpdateParameters>
  76.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  77.     PropertyName="Text"/>
  78.   </UpdateParameters>
  79.   <DeleteParameters>
  80.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  81.     PropertyName="Text"/>
  82.   </DeleteParameters>
  83.  
  84. </asp:AccessDataSource>
  85.  
  86. <asp:GridView id="ShopCartGrid" DataSourceID="ShopCartSource" Runat="Server"
  87.   AutoGenerateColumns="False"
  88.   DataKeyNames="OrderNumber,HostaID" 
  89.   onrowupdating="Shopcart_RowUpdating"
  90.   onrowdeleting="Shopcart_Rowdeleting"
  91.   Cellpadding="3"
  92.   ShowFooter="True"
  93. >
  94.   <Columns>
  95.  
  96.   <asp:TemplateField
  97.     HeaderText="Name" HeaderStyle-HorizontalAlign="Left" 
  98.     ItemStyle-Width="150">
  99.     <ItemTemplate>
  100.       <asp:Label ID="Label4" Runat="Server" EnableViewState="False" 
  101.         Text='<%# Bind("Naam") %>'/>
  102.     </ItemTemplate>
  103.     <EditItemTemplate>
  104.       <asp:Label ID="Label5" Runat="Server" EnableViewState="False" 
  105.         Text='<%# Bind("Naam") %>'/>
  106.     </EditItemTemplate>
  107.     </asp:TemplateField>
  108.  
  109.   <asp:TemplateField
  110.     HeaderText="Photo" HeaderStyle-HorizontalAlign="Left" 
  111.     ItemStyle-Width="50">
  112.      <ItemTemplate>
  113.         <asp:Image ImageUrl='<%# Eval("Naam", "http://www.hostaparadise.com/images/thumbs/{0}.jpg") %>' EnableViewState="False"  runat="server"/>
  114.     </ItemTemplate>
  115.   </asp:TemplateField>
  116.  
  117.   <asp:TemplateField
  118.     HeaderText="Price"
  119.     ItemStyle-HorizontalAlign="Right" 
  120.     ItemStyle-Width="50">
  121.     <ItemTemplate>
  122.       <asp:Label ID="Label6" Runat="Server" EnableViewState="False" 
  123.         Text='<%# String.Format("€ {0:C},00", Eval("Prijs")) %>'/>
  124.     </ItemTemplate>
  125.     <EditItemTemplate>
  126.       <asp:Label ID="Label7" Runat="Server" EnableViewState="False" 
  127.         Text='<%# String.Format("€ {0:C},00", Eval("Prijs")) %>'/>
  128.     </EditItemTemplate>
  129.   </asp:TemplateField>
  130.  
  131.   <asp:TemplateField
  132.     HeaderText="Number" 
  133.     ItemStyle-Width="60"
  134.     FooterStyle-HorizontalAlign="Right"
  135.     ItemStyle-HorizontalAlign="Right">
  136.     <ItemTemplate>
  137.       <asp:Label ID="Label8" Runat="Server" EnableViewState="False" 
  138.         Text='<%# String.Format("{0:D}", Eval("Aantal")) %>'
  139.         Width="25" Font-Size="9pt" Style="text-align:right"/>
  140.     </ItemTemplate>
  141.     <EditItemTemplate>
  142.       <asp:TextBox id="Number" Runat="Server" EnableViewState="False" 
  143.         Text='<%# Bind("Aantal") %>'
  144.         MaxLength="4" Width="25" Height="17" Font-Size="9pt"
  145.         Style="padding:0px; text-align:right"/>
  146.  
  147.     </EditItemTemplate>
  148.  
  149.     <FooterTemplate>
  150.       <asp:Label ID="Label10" Text="Total" Runat="Server" EnableViewState="False"
  151.         Font-Bold="True" Width="50" BorderStyle="Solid" BorderWidth="0" 
  152.         Style="padding:2px; margin-top:5px"/>
  153.     </FooterTemplate>
  154.   </asp:TemplateField>
  155.  
  156.  
  157.   <asp:TemplateField HeaderText="Amount" 
  158.     ItemStyle-Width="80"
  159.     ItemStyle-HorizontalAlign="Right"
  160.     FooterStyle-HorizontalAlign="Right">
  161.     <ItemTemplate>
  162.       <asp:Label ID="Label11" Runat="Server" EnableViewState="False" 
  163.         Text='<%# String.Format("{0:C}", _
  164.                   Get_Amount(Eval("Prijs"), Eval("Aantal"))) %>'/>
  165.     </ItemTemplate>
  166.     <EditItemTemplate>
  167.       <asp:Label ID="Label12" Runat="Server" EnableViewState="False" 
  168.         Text='<%# String.Format("{0:C}", _
  169.                   Get_Amount(Eval("Prijs"), Eval("Aantal"))) %>'/>
  170.     </EditItemTemplate>
  171.     <FooterTemplate>
  172.       <asp:Label id="OrderTotal" Runat="Server"
  173.         Text='<%# String.Format("{0:C}", Get_Order_Total()) %>' 
  174.         Width="80" Font-Bold="True" BorderStyle="Solid" BorderWidth="1"
  175.         BorderColor="#C0C0C0" Style="padding:2px; margin-top:5px"/>
  176.     </FooterTemplate>
  177.   </asp:TemplateField>
  178.  
  179.   <asp:TemplateField
  180.     HeaderText="Modify order"
  181.     ItemStyle-Width="110"
  182.     FooterStyle-BackColor="#E0E0E0">
  183.     <ItemTemplate>
  184.       <asp:Button ID="Button1" Text="Change" CommandName="Edit" Runat="Server"
  185.         Font-Size="7pt" Width="50"/>
  186.       <asp:Button ID="Button2" Text="Delete" CommandName="Delete" Runat="Server"
  187.         Font-Size="7pt" Width="50"/>
  188.     </ItemTemplate>
  189.     <EditItemTemplate>
  190.       <asp:Button ID="Button3" Text="Update" CommandName="Update" Runat="Server"
  191.         Font-Size="7pt" Width="50"/>
  192.       <asp:Button ID="Button4" Text="Cancel" CommandName="Cancel" Runat="Server"
  193.         Font-Size="7pt" Width="50"/>
  194.     </EditItemTemplate>
  195.     <FooterTemplate>
  196.       <asp:Button ID="Button5" Text="Finalise order »" OnClick="Submit_Form"  EnableViewState="False" Runat="Server" Font-Size="8pt" Width="75" Style="margin-top:22px"/>
  197.  
  198.     </FooterTemplate>
  199.   </asp:TemplateField>
  200.  
  201.   </Columns>
  202.  
  203. </asp:GridView>
  204.  
  205.  
  206.   </form>
  207. </body>
  208. </html>
Mar 17 '08 #1
0 1970

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

Similar topics

3
2972
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed to load viewstate" error. This happens on Windows Server 2003. It happens erratically, and appears to happen after the application has been running...
9
21630
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario...
1
3852
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this using a GridView that has ViewState enabled, an ObjectDataSource to process the submitted list, textboxes for getting new item data and an add button. ...
6
2058
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 page gets post back it gives following error Failed to load viewstate. The control tree into which viewstate is
0
1414
by: surfr | last post by:
The page of gridview can stand-alone running and pageing,when i place it to content and click page 2 server display : Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a...
6
2925
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page has expired instead of getting the error? Thanks,
2
4481
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
12
3791
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values in my 'onpageload' in the cs file.
0
1646
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the item which was selected in the previous run the following error message is displayed.. Please help me in this regard.. Failed to load viewstate. ...
0
7520
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...
0
7718
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. ...
1
7470
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...
0
7809
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...
1
5368
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...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1936
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
0
763
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...

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.