LinkButton in DataGrid not executing eventhandler

Discussion in 'ASP .Net Datagrid Control' started by Al Cadalzo, Jan 3, 2004.

  1. Al Cadalzo

    Al Cadalzo Guest

    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 Cadalzo, Jan 3, 2004
    1. Advertisements

  2. Al Cadalzo

    Teemu Keiski Guest


    that is probably because Command event raises DataGrid's ItemCommand event.
    Is that raised even if ViewState is disabled?
    Teemu Keiski, Jan 4, 2004
    1. Advertisements

  3. Al Cadalzo

    Al Cadalzo Guest

    I see nothing in the docs that says that ViewState has to be enabled in
    order for the event to be raised.
    Al Cadalzo, Jan 5, 2004
  4. Al Cadalzo

    Teemu Keiski Guest


    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
    Teemu Keiski, Jan 5, 2004
  5. 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.
    David Mc Kenzie, Jan 7, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.