Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > running client side script after an <asp:ButtonColumn> click event

Reply
Thread Tools

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

 
 
Steven Spits
Guest
Posts: n/a
 
      06-22-2004
"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

- - -



 
Reply With Quote
 
 
 
 
Steven Spits
Guest
Posts: n/a
 
      06-22-2004
"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

- - -


 
Reply With Quote
 
 
 
 
z. f.
Guest
Posts: n/a
 
      06-22-2004
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.


 
Reply With Quote
 
Steven Spits
Guest
Posts: n/a
 
      06-22-2004
"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

- - -


 
Reply With Quote
 
Steven Spits
Guest
Posts: n/a
 
      06-22-2004
"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

- - -


 
Reply With Quote
 
z. f.
Guest
Posts: n/a
 
      06-22-2004
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
>
> - - -
>
>
>



 
Reply With Quote
 
z. f.
Guest
Posts: n/a
 
      06-22-2004
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
> >
> > - - -
> >
> >
> >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button disabled and re-enabled in client side not firing server-side click event. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= ASP .Net 2 05-27-2008 09:57 AM
When user press F5 after a button click event, the click event fires again! Max2006 ASP .Net 2 09-19-2007 05:37 AM
Client side script after client side validation with asp.net 2.0 Boss302 ASP .Net 0 11-21-2006 08:43 AM
running client side script after an <asp:ButtonColumn> click event Steven Spits ASP .Net 6 06-22-2004 02:28 PM
asp:button w/ client side and server side click event Aymer ASP .Net Web Controls 1 09-19-2003 03:10 PM



Advertisments