473,326 Members | 2,081 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,326 software developers and data experts.

DataGrid Viewstate

kpg
Hola,

I have a datagrid with button columns. I bind the data on
page load, and the table is read only, so I don't need the
datagrid viewstate enabled. When I turn it off however, I
no longer get the button click events. I know events are
passed in the viewstate, but I don't need the data saved in
the viewstate, it adds a considerable amount of data to the
page.

Can I tunn off the datagrid viewstate and still respond to
button column events?

kpg
Jun 5 '06 #1
4 1416
As long as you can provide a mechanism for the DG state to be restored by
PageLoad, the event will fire. Without viewstate DG can't restore its state.
http://www.netomatix.com
"kpg" <no@way.com> wrote in message
news:Xn*******************************@207.46.248. 16...
Hola,

I have a datagrid with button columns. I bind the data on
page load, and the table is read only, so I don't need the
datagrid viewstate enabled. When I turn it off however, I
no longer get the button click events. I know events are
passed in the viewstate, but I don't need the data saved in
the viewstate, it adds a considerable amount of data to the
page.

Can I tunn off the datagrid viewstate and still respond to
button column events?

kpg

Jun 5 '06 #2
kpg
As Winista once said in microsoft.public.dotnet.framework.aspnet
As long as you can provide a mechanism for the DG state to be restored
by PageLoad, the event will fire. Without viewstate DG can't restore
its state.
http://www.netomatix.com

OK, but when I click the button on the datagrid, I get a postback, but
neither the DataGrid1_ItemCommand nor DataGrid1_SelectedIndexChanged
events get called.

All I need to know from the page is which column the user clicked
on, but this info seems to be lost without viewstate enabled.

Jun 5 '06 #3
Exactly... if DataGrid state is not resored or for that matter page's state
is not restored, framework does not know where to send the message. You can
use approach where you can set custom IDs or string in __EVENTTARGET and
__EVENTARGS hideen variables from client side when click happens and then on
server you can look for these values to decide from where the event
originated.

"kpg" <no@way.com> wrote in message
news:Xn*******************************@207.46.248. 16...
As Winista once said in microsoft.public.dotnet.framework.aspnet
As long as you can provide a mechanism for the DG state to be restored
by PageLoad, the event will fire. Without viewstate DG can't restore
its state.
http://www.netomatix.com

OK, but when I click the button on the datagrid, I get a postback, but
neither the DataGrid1_ItemCommand nor DataGrid1_SelectedIndexChanged
events get called.

All I need to know from the page is which column the user clicked
on, but this info seems to be lost without viewstate enabled.

Jun 5 '06 #4
kpg
As Winista once said in microsoft.public.dotnet.framework.aspnet
Works great!
In the DataGrid1_ItemDataBound event I added (see ref below):
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then

Dim myButton As Button = e.Item.Cells(0).Controls(0)

myButton.Attributes("onclick") = _
"javascript: document.getElementById ('__EVENTTARGET').value=" & _
DataBinder.Eval(e.Item.DataItem, "UserID") & ";"

End If

and in the Page_Load (see ref below):

Dim strTest As String = Page.Request.Params("__EVENTTARGET")
Ref:

http://aspnet.4guysfromrolla.com/art...90402-1.2.aspx
http://www.eggheadcafe.com/articles/20050609.asp
Thanks.
Jun 5 '06 #5

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

Similar topics

3
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is...
4
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
2
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
3
by: Raymond Lewallen | last post by:
I have a modal dialog displaying a datagrid control. Click on the column header to sort the datagrid opens a new window with the following in the location: ...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
4
by: Luis Esteban Valencia | last post by:
I have a asp.net page (C#), with a datagrid. I use template for all columns, and have <asp:requiredfieldvalidator> in with one of the textboxes, to make sure it's filled in. However, this...
6
by: sonic | last post by:
Hi, I am experimenting with different viewstate management ideas for large datagrids, and found a microsoft suggestion to turn it off, and only store relevant information by manually accessing...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.