473,395 Members | 1,457 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,395 software developers and data experts.

overriden viewstate events and gridview

Hi,
I’m implementing SavePageStateToPersistenceMedium and
LoadPageStateFromPersistenceMedium in asp.net 2.0 to increment performance
avoiding sending viewstate of pages to browser.
The code I use is:
protected override void SavePageStateToPersistenceMedium(object state)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Cache.Add(str, state, null,
DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
System.Web.Caching.CacheItemPriority.Normal, null);
ClientScript.RegisterHiddenField("__VIEWSTATE_KEY" , str);
// this hidden indetifies the unique id which viewstate is saved in
server.
ClientScript.RegisterHiddenField("__VIEWSTATE", "")
}

And LoadPageStateFromPersistenceMedium:

protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
return null;
}
return Cache[str];
}

I have a problem in one page with a usercontrol that contains a gridview
bounded to a dataview. This gridview has asigned a DataKeyName in the onInit
event of the usercontrol:

gvVista.DataSource = mView;
string[] sKeyFields = { “keyFieldName” };
gvVista.DataKeyNames = sKeyFields;

The problem is that in the SelectedIndexChanged event I can’t catch de ID
Selected by User.

protected void gvVista_SelectedIndexChanged(object sender, EventArgs e)
{
int index = Convert.ToInt32(gvVista.SelectedIndex);
int iID = Convert.ToInt32(gvVista.DataKeys[index].Value);
}

This code allways throws the exception
“Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index”

That because DataKeys is empty.

If I comment the viewstate events overriden in the page, the page works fine.

Why does the overriden viewstate events “delete” de datakeys value or what
I’m doing bad?

Thanks a lot.

Marcelo

May 4 '06 #1
0 1153

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

Similar topics

6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
0
by: Jj | last post by:
Hi, I'm looking for articles or sample code to reduce the viewstate usage in ASP.NET 2 I want to use the treeview + gridview to create a hierarchical display of my data. The grid(s) can be...
1
by: cheloman12 | last post by:
Hi, I posted this problem some days ago. I repeat it because it was no answered. If description is confused, please make me know and i'll try to explain the case better. Thanks a lot, Marcelo...
4
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to...
4
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to...
2
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...
12
by: Bob Jones | last post by:
I have an odd business requirement and I think that the implementation is not correct in the terms of OOP development. Any help on the concepts would be very appreciated! We currently have a...
2
by: Tim Royal | last post by:
I'm using a GridView inside a Wizard Control with a textbox and two listboxes in the footer. I populate these listboxes from the database if the page isn't on postback (and the textbox is left...
2
by: msch.prv | last post by:
Thanks for bearing with me. I am confronted with huge hidden viewstates fields in some pages and looking for ways to make these pages leaner. My problem hinges on how to efficiently handle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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,...
0
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...
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...
0
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...
0
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...

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.