LinkButton in DataGrid not executing eventhandler

A

Al Cadalzo

I have a datagrid with some BoundColumns and several TemplateColumn's. Each
template column has a linkButton with the event handler specified via
OnCommand="ExternalLink_Command". The LinkButtons also have CommandName and
CommandArgument attributes set. Clicking on the linkbuttons causes a
postback, but the event handler is not executed. If I set the
EnableViewState on the datagrid to True, then it executes the event handler.
I do not want to have to set EnableViewState to True on the datagrid as it
slows the page down considerably. Oddly enough I have another datagrid on
the same page with a linkbutton and it executes the OnClick event handler
fine without having to set EnableViewState to "True".

Thanks for any help or suggestions you can offer.
Al
 
T

Teemu Keiski

Hi,

that is probably because Command event raises DataGrid's ItemCommand event.
Is that raised even if ViewState is disabled?
 
A

Al Cadalzo

I see nothing in the docs that says that ViewState has to be enabled in
order for the event to be raised.
 
T

Teemu Keiski

Hi,

It was question that is it raised in your case. And docs don't tell
everything. :)

If you set CommandName and CommandArgument properties for LinkButton that is
in Datagrid, DataGrid's ItemCommand event is raised with the given
arguments. You might want try to handle that.

Anyway, here's couple of articles that discuss about using DataGrid without
ViewState:
http://authors.aspalliance.com/jimross/Articles/DatagridDiet.aspx
http://authors.aspalliance.com/jimross/Articles/DatagridDietPartTwo.aspx
 
D

David Mc Kenzie

What tripped me up with WEB DataGrid events was the fact that the
datagrid will not work if it is not bound to something. With the save
viewstate off, when the datagrid returns, the data is not persisted, and
the datagrid does nothing because it is not bound. Sometimes, depending
on where you store the data, the data is persisted anyway using that
object's viewstate, and then it works. To test if this is the problem -
simply bind the datagrid to some data in the oninit event. I use rubbish
data to get mine to work properly.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top