running client side script after an <asp:ButtonColumn> click event

Discussion in 'ASP .Net Datagrid Control' started by Steven Spits, Jun 22, 2004.

  1. Steven Spits

    Steven Spits Guest

    "z. f." wrote

    > i have a datagrid with a delete button for each row in the grid.
    > when the delete button is clicked i need to ask the user in a "confirm"
    > message box if he's sure he wants to delete.


    Get a reference to the delete button in the ItemCreated event of your
    datagrid, then use:

    btnDelete.Attributes.Add("onclick", "return confirm('Delete record?');");

    Steven

    - - -
     
    Steven Spits, Jun 22, 2004
    #1
    1. Advertising

  2. Steven Spits

    Steven Spits Guest

    "z. f." wrote:

    > how would you get a reference to the buttoncolumn since it does not have

    an
    > ID attribute
    >
    > <asp:ButtonColumn Text="del" ButtonType="PushButton"
    > CommandName="Delete"></asp:ButtonColumn>
    >
    > and also the findControl method would not cast to the boundColumn type of
    > the button - the following line of code will not compile:
    > Dim btn As System.Web.UI.WebControls.ButtonColumn =
    > CType(e.Item.FindControl("btnDelIDIDID"), ButtonColumn)


    Dim btnDelete As Button = CType(e.Item.Cells(0).Controls(0), Button)

    Modify the indexes!

    Steven

    - - -
     
    Steven Spits, Jun 22, 2004
    #2
    1. Advertising

  3. Steven Spits

    z. f. Guest

    Hi,

    i have a datagrid with a delete button for each row in the grid.
    when the delete button is clicked i need to ask the user in a "confirm"
    message box if he's sure he wants to delete.
    the problem is that the
    <asp:ButtonColumn ButtonType="PushButton" CommandName="Delete" .... don't
    have a property to allow onclick to run client side script . how can this
    be,

    an i missing here something, cause there must be a way to do this without
    implementing the button on my own!

    TIA, z.
     
    z. f., Jun 22, 2004
    #3
  4. Steven Spits

    Steven Spits Guest

    "z. f." wrote:

    > but somewhere i get the feeling that getting
    > to the button using it's index (that might change
    > tomorrow) and having to take care of this index in
    > order that when it changed the code will not fail is
    > not the state of the art programming practice,


    Use a foreach to loop all cells and all controls in each cell to search for
    your button. You could use the CommandName or CommandArgument as a
    search-criteria.

    Steven

    - - -
     
    Steven Spits, Jun 22, 2004
    #4
  5. Steven Spits

    Steven Spits Guest

    "Steven Spits" wrote:

    > Use a foreach to loop all cells and all controls in each cell to search
    > for your button. You could use the CommandName or
    > CommandArgument as a search-criteria.


    *or* you could also use a TemplateColumn and put a normal button in it,
    which can be given an ID. That way, you could use FindControl().

    Steven

    - - -
     
    Steven Spits, Jun 22, 2004
    #5
  6. Steven Spits

    z. f. Guest

    how would you get a reference to the buttoncolumn since it does not have an
    ID attribute

    <asp:ButtonColumn Text="del" ButtonType="PushButton"
    CommandName="Delete"></asp:ButtonColumn>

    and also the findControl method would not cast to the boundColumn type of
    the button - the following line of code will not compile:
    Dim btn As System.Web.UI.WebControls.ButtonColumn =
    CType(e.Item.FindControl("btnDelIDIDID"), ButtonColumn)

    TIA,





    "Steven Spits" <> wrote in message
    news:...
    > "z. f." wrote
    >
    > > i have a datagrid with a delete button for each row in the grid.
    > > when the delete button is clicked i need to ask the user in a "confirm"
    > > message box if he's sure he wants to delete.

    >
    > Get a reference to the delete button in the ItemCreated event of your
    > datagrid, then use:
    >
    > btnDelete.Attributes.Add("onclick", "return confirm('Delete record?');");
    >
    > Steven
    >
    > - - -
    >
    >
    >
     
    z. f., Jun 22, 2004
    #6
  7. Steven Spits

    z. f. Guest

    the way i did got a reference to the button is:
    Dim btn As System.Web.UI.WebControls.Button = e.Item.Cells(4).Controls(0)

    btn.Attributes.Add("onclick", "return confirm('Delete record?');")

    btn.CausesValidation = False (this doesn't work - how can i do this is another question.)



    but somewhere i get the feeling that getting to the button using it's index (that might change tomorrow) and having to take care of this index in order that when it changed the code will not fail is not the state of the art programming practice, i wish someone in this newsgroup will state the microsoft engineers opinion regarding us having to program this way!





    "z. f." <> wrote in message news:%...
    > how would you get a reference to the buttoncolumn since it does not have an
    > ID attribute
    >
    > <asp:ButtonColumn Text="del" ButtonType="PushButton"
    > CommandName="Delete"></asp:ButtonColumn>
    >
    > and also the findControl method would not cast to the boundColumn type of
    > the button - the following line of code will not compile:
    > Dim btn As System.Web.UI.WebControls.ButtonColumn =
    > CType(e.Item.FindControl("btnDelIDIDID"), ButtonColumn)
    >
    > TIA,
    >
    >
    >
    >
    >
    > "Steven Spits" <> wrote in message
    > news:...
    > > "z. f." wrote
    > >
    > > > i have a datagrid with a delete button for each row in the grid.
    > > > when the delete button is clicked i need to ask the user in a "confirm"
    > > > message box if he's sure he wants to delete.

    > >
    > > Get a reference to the delete button in the ItemCreated event of your
    > > datagrid, then use:
    > >
    > > btnDelete.Attributes.Add("onclick", "return confirm('Delete record?');");
    > >
    > > Steven
    > >
    > > - - -
    > >
    > >
    > >

    >
    >
     
    z. f., Jun 22, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,499
    rick74
    May 27, 2008
  2. Steven Spits
    Replies:
    6
    Views:
    4,490
    z. f.
    Jun 22, 2004
  3. Boss302
    Replies:
    0
    Views:
    1,061
    Boss302
    Nov 21, 2006
  4. Max2006
    Replies:
    2
    Views:
    1,585
    Walter Wang [MSFT]
    Sep 19, 2007
  5. Aymer
    Replies:
    1
    Views:
    391
    Alvin Bruney
    Sep 19, 2003
Loading...

Share This Page