473,837 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView problems with viewstate events overriden.

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

"I’m implementing SavePageStateTo PersistenceMedi um and
LoadPageStateFr omPersistenceMe dium in asp.net 2.0 to increment performance
avoiding sending viewstate of pages to browser.
The code I use is:
protected override void SavePageStateTo PersistenceMedi um(object state)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Cache.Add(str, state, null,
DateTime.Now.Ad dMinutes(Sessio n.Timeout), TimeSpan.Zero,
System.Web.Cach ing.CacheItemPr iority.Normal, null);
ClientScript.Re gisterHiddenFie ld("__VIEWSTATE _KEY", str);
// this hidden indetifies the unique id which viewstate is saved in
server.
ClientScript.Re gisterHiddenFie ld("__VIEWSTATE ", "")
}

And LoadPageStateFr omPersistenceMe dium:

protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("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.DataSou rce = mView;
string[] sKeyFields = { “keyFieldName ” };
gvVista.DataKey Names = sKeyFields;

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

protected void gvVista_Selecte dIndexChanged(o bject sender, EventArgs e)
{
int index = Convert.ToInt32 (gvVista.Select edIndex);
int iID = Convert.ToInt32 (gvVista.DataKe ys[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 10 '06 #1
1 2776
Hi,

instead of overriding SavePageStatexx x and LoadPageStateFr omxxx use this on
the Page to override PageStatePersis ter property

protected override PageStatePersis ter PageStatePersis ter
{
get
{
return new SessionPageStat ePersister(this );
}
}

It's built-in ASP.NET and saves the state into Session instead hidden form
field (HiddenFieldPag eStatePersister , the default)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"cheloman12 " <ch********@dis cussions.micros oft.com> wrote in message
news:A5******** *************** ***********@mic rosoft.com...
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

"I'm implementing SavePageStateTo PersistenceMedi um and
LoadPageStateFr omPersistenceMe dium in asp.net 2.0 to increment performance
avoiding sending viewstate of pages to browser.
The code I use is:
protected override void SavePageStateTo PersistenceMedi um(object state)
{
string str = "VIEWSTATE_ " + Request.UserHos tAddress + "_" +
DateTime.Now.Ti cks.ToString();
Cache.Add(str, state, null,
DateTime.Now.Ad dMinutes(Sessio n.Timeout), TimeSpan.Zero,
System.Web.Cach ing.CacheItemPr iority.Normal, null);
ClientScript.Re gisterHiddenFie ld("__VIEWSTATE _KEY", str);
// this hidden indetifies the unique id which viewstate is saved in
server.
ClientScript.Re gisterHiddenFie ld("__VIEWSTATE ", "")
}

And LoadPageStateFr omPersistenceMe dium:

protected override object LoadPageStateFr omPersistenceMe dium()
{
string str = Request.Form["__VIEWSTATE_KE Y"];
if (!str.StartsWit h("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.DataSou rce = mView;
string[] sKeyFields = { "keyFieldNa me" };
gvVista.DataKey Names = sKeyFields;

The problem is that in the SelectedIndexCh anged event I can't catch de ID
Selected by User.

protected void gvVista_Selecte dIndexChanged(o bject sender, EventArgs e)
{
int index = Convert.ToInt32 (gvVista.Select edIndex);
int iID = Convert.ToInt32 (gvVista.DataKe ys[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 10 '06 #2

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

Similar topics

1
3871
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. Does this approach sound feasible or are there better alternatives? My problem is that I don't...
9
24826
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the page life cycle. In this example the event fires twice when a) GridView EnableViewState=False and any image type control in the <columns/> element. When either EnableViewState is set to true or the image button is removed, the event fires once....
0
1175
by: cheloman12 | last post by:
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,
1
3255
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
13
42079
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The footer template has an commandbutton with the commandname set to 'Insert'. Both buttons cause postback, however the RowCommand event does not fire. How can I get the rowcommand to fire?
0
1771
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
3
22758
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work. I turned on the Allow Sorting property but when I click one of the columns that is bound, it will not sort. Below is the code I am using
2
3510
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 blank initially). All of these controls have viewstate enabled. When the user fills out the textfield and clicks ADD, I do a check for validation of the data. If the user does not select a valid listbox entry, I abort the rest of the add, and make...
3
5249
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
9851
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9695
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
10583
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
10642
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
9420
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 projectplanning, coding, testing, and deploymentwithout 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
7824
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...
0
7013
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
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.