DataGrid event fireing

A

andla

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 to think how does .Net do it if I turn the viewstat
on.

If you use the Request.Form then you can get all the controls tha
existed in the previous postback and the hidden field with viewstate.
suspect that the event is embedded in this viewstate or something tha
will create events to fire in the codebehind.

I would appreciate some help in figuring out how this machinery works
Then maybe it is possible to handle this downside with datagrid.

Yours sincerely
Andl

andl
 
A

Alvin Bruney [MVP]

datagrid events fire off when they are hooked to their specific events.
in the initializecomponent section you will see this
datagrid.itemdatabound += new some stuff (itemdataboundeventhandler)

this tells the machinery that when ever the itemdatabound fires off in the
datagrid, call the code in itemdataboundeventhandler found in the
codebehind. when you turn off viewstate, it doesn't remember this line, so
the events don't call any code. so before you bind you have to manually
rehook the events using

datagrid.itemdatabound += new some stuff (itemdataboundeventhandler)

makes sense?
 
M

Marshal Antony

Hi Andla,
The viewstate is maintained automatically across postbacks by the
ASP.NET Framework.
The viewstate is read when a page is posted to the server.The viewstate is
restored just before the page is
sent back to the browser.
The viewstate is saved in the state bag using hidden
fields that contain state encoded in a string variable.
State Bag is a data structure containing attribute/value pairs,stored as
string associated with objects.
If you want to preserve the values which are not associated with
any particular control
and if you wish to preserve those values across postbacks you can store
these values is the Pages's state bag.
For example when an Itemcommand event happens in your
datagrid,the browser handles the client side event
to post back to the server which send an event message to the server as
well.Viewstate information is used in handling events.
The server determines if the Itemcommand event has an event
handler associated with it and if there is,the event handler code
is executed at the server.The event message is send to the server by HTTP
POST.ASP.NET automatically do all this for you.What
you have to do is create your event handlers.
Since there is data posted back and forth with every
post,if there is large amount of data you need to handle,
in your datagrid with the EnnableViewState is true ,the page loading can be
very slow and the page size can be too big.
You could use paging in scenarios like this if needed.
However you can disable view state of the datagrid and handle
events using certain guidelines.
Here is an article on this :

http://authors.aspalliance.com/JimRoss/Articles/DatagridDiet.aspx

Hope this helps.

Marshal Antony
..NET Developer
http://www.dotnetmarshal.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top