From: Eric on
Hi,

I have a gridview with the last column to be a buttonfield.
This is a delete button.
When the user clicks it, the RowCommand event will be fired and the
rowcommand property holds the line number.

I would like from the rowcommand event, to show a popup asking the user if
he wants to continue, like a javascript confirm box.
I can put up the box with

ClientScript.RegisterStartupScript(Me.GetType(), "confirm",
"<script>confirm('" + Msg + "');</script>")

but how can I get it to go to link1 if the answer is ok?

something like: ok pressed --> "~\default.aspx?userclickedOK=true"

is this at all possible?

rg,
Eric

From: Mark Rae [MVP] on
"Eric" <Eric(a)discussions.microsoft.com> wrote in message
news:E9478525-6F62-464D-9E1B-7A037EF79084(a)microsoft.com...

> I have a GridView where the last column is a ButtonField.
> This is a delete button.
> When the user clicks it, the RowCommand event will be fired and the
> rowcommand property holds the line number.
>
> I would like from the rowcommand event, to show a popup asking the user if
> he wants to continue, like a javascript confirm box.
> I can put up the box with
>
> ClientScript.RegisterStartupScript(Me.GetType(), "confirm",
> "<script>confirm('" + Msg + "');</script>")
>
> but how can I get it to go to link1 if the answer is ok?
>
> something like: ok pressed --> "~\default.aspx?userclickedOK=true"
>
> Is this at all possible?

Yes, but you're making things unnecessarily complicated...

<Columns>
<%-- other columns --%>
<asp:TemplateField HeaderText="" ItemStyle-Wrap="False">
<ItemTemplate>
<asp:Button ID="cmdDelete" runat="server" Text="Del"
OnCommand="cmdDelete_Command" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ID").ToString()%>'
OnClientClick="return confirm('Are you sure you want to delete this
record?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>

protected void cmdDelete_Command(object sender, CommandEventArgs e)
{
// ID to be deleted is e.CommandArgument.ToString()
}

No need for RowCommand or anything like that...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: Alexey Smirnov on
On Dec 18, 11:19 am, Eric <E...(a)discussions.microsoft.com> wrote:
> Hi,
>
> I have a gridview with the last column to be a buttonfield.
> This is a delete button.
> When the user clicks it, the RowCommand event will be fired and the
> rowcommand property holds the line number.
>
> I would like from the rowcommand event, to show a popup asking the user if
> he wants to continue, like a javascript confirm box.
> I can put up the box with
>
> ClientScript.RegisterStartupScript(Me.GetType(), "confirm",
> "<script>confirm('" + Msg + "');</script>")
>
> but how can I get it to go to link1 if the answer is ok?
>
> something like: ok pressed --> "~\default.aspx?userclickedOK=true"
>
> is this at all possible?
>
> rg,
> Eric

Hi Eric,

you can do it from the code behind, using RowDataBound method. Here's
an example on VB

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
If (e.Row.RowState = DataControlRowState.Normal Or
e.Row.RowState = DataControlRowState.Alternate) Then
Dim l As LinkButton = e.Row.Cells(0).Controls(0) <----
this must be change acc. to your grid setup
l.Attributes.Add("onclick", "javascript:return confirm
('Are you sure?')") <--- this is your confirm script
End If
End If
End Sub

If user pressed OK then RowDeleting Event get fired

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
....
End Sub

and this is where you can programmatically redirect to the new page.

Hope this helps
From: Eric on


"Alexey Smirnov" wrote:

> On Dec 18, 11:19 am, Eric <E...(a)discussions.microsoft.com> wrote:
> > Hi,
> >
> > I have a gridview with the last column to be a buttonfield.
> > This is a delete button.
> > When the user clicks it, the RowCommand event will be fired and the
> > rowcommand property holds the line number.
> >
> > I would like from the rowcommand event, to show a popup asking the user if
> > he wants to continue, like a javascript confirm box.
> > I can put up the box with
> >
> > ClientScript.RegisterStartupScript(Me.GetType(), "confirm",
> > "<script>confirm('" + Msg + "');</script>")
> >
> > but how can I get it to go to link1 if the answer is ok?
> >
> > something like: ok pressed --> "~\default.aspx?userclickedOK=true"
> >
> > is this at all possible?
> >
> > rg,
> > Eric
>
> Hi Eric,
>
> you can do it from the code behind, using RowDataBound method. Here's
> an example on VB
>
> Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
> e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
> GridView1.RowDataBound
> If (e.Row.RowType = DataControlRowType.DataRow) Then
> If (e.Row.RowState = DataControlRowState.Normal Or
> e.Row.RowState = DataControlRowState.Alternate) Then
> Dim l As LinkButton = e.Row.Cells(0).Controls(0) <----
> this must be change acc. to your grid setup
> l.Attributes.Add("onclick", "javascript:return confirm
> ('Are you sure?')") <--- this is your confirm script
> End If
> End If
> End Sub
>
> If user pressed OK then RowDeleting Event get fired
>
> Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal
> e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
> GridView1.RowDeleting
> ....
> End Sub
>
> and this is where you can programmatically redirect to the new page.
>
> Hope this helps
> .
>

Hi,

I applied this code to my page.
When the user clicks on de delete button, the popup does appear. Clicking on
cancel will just remove the popup, clicking on OK does a page refresh, but
the RowDeleting event is not fired.

How can I get it fired?

here is my code about the creation of the column:
Dim clBT As New ButtonField
clBT.HeaderText = ""
clBT.HeaderStyle.BackColor = gridbackcolor
clBT.HeaderStyle.ForeColor = gridforecolor
clBT.HeaderStyle.Font.Name = "Arial"
clBT.HeaderStyle.Font.Bold = True
clBT.HeaderStyle.Font.Size = fontsize
clBT.Text = "delete"
clBT.ItemStyle.Font.Size = 8
clBT.ItemStyle.Font.Name = "Arial"
clBT.ItemStyle.Font.Underline = True
clBT.ButtonType = ButtonType.Link
clBT.ItemStyle.Width = 40
clBT.ItemStyle.HorizontalAlign = HorizontalAlign.Center
ctrl.Columns.Add(clBT)

where ctrl is the gridview.
This is the 14th column.

The following is in the RowDatabound event:

If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState =
DataControlRowState.Alternate Then
Try
If e.Row.Cells(14).Controls.Count > 0 Then
Dim lb As LinkButton = e.Row.Cells(14).Controls(0)
lb.Attributes.Add("onclick", "javascript:return confirm('Are you
sure?')")
End If
Catch ex As Exception
End Try
End If
End If

What can I do now?

rg,
Eric
From: Eric on


"Eric" wrote:

>
>
> "Alexey Smirnov" wrote:
>
> > On Dec 18, 11:19 am, Eric <E...(a)discussions.microsoft.com> wrote:
> > > Hi,
> > >
> > > I have a gridview with the last column to be a buttonfield.
> > > This is a delete button.
> > > When the user clicks it, the RowCommand event will be fired and the
> > > rowcommand property holds the line number.
> > >
> > > I would like from the rowcommand event, to show a popup asking the user if
> > > he wants to continue, like a javascript confirm box.
> > > I can put up the box with
> > >
> > > ClientScript.RegisterStartupScript(Me.GetType(), "confirm",
> > > "<script>confirm('" + Msg + "');</script>")
> > >
> > > but how can I get it to go to link1 if the answer is ok?
> > >
> > > something like: ok pressed --> "~\default.aspx?userclickedOK=true"
> > >
> > > is this at all possible?
> > >
> > > rg,
> > > Eric
> >
> > Hi Eric,
> >
> > you can do it from the code behind, using RowDataBound method. Here's
> > an example on VB
> >
> > Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
> > e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
> > GridView1.RowDataBound
> > If (e.Row.RowType = DataControlRowType.DataRow) Then
> > If (e.Row.RowState = DataControlRowState.Normal Or
> > e.Row.RowState = DataControlRowState.Alternate) Then
> > Dim l As LinkButton = e.Row.Cells(0).Controls(0) <----
> > this must be change acc. to your grid setup
> > l.Attributes.Add("onclick", "javascript:return confirm
> > ('Are you sure?')") <--- this is your confirm script
> > End If
> > End If
> > End Sub
> >
> > If user pressed OK then RowDeleting Event get fired
> >
> > Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal
> > e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
> > GridView1.RowDeleting
> > ....
> > End Sub
> >
> > and this is where you can programmatically redirect to the new page.
> >
> > Hope this helps
> > .
> >
>
> Hi,
>
> I applied this code to my page.
> When the user clicks on de delete button, the popup does appear. Clicking on
> cancel will just remove the popup, clicking on OK does a page refresh, but
> the RowDeleting event is not fired.
>
> How can I get it fired?
>
> here is my code about the creation of the column:
> Dim clBT As New ButtonField
> clBT.HeaderText = ""
> clBT.HeaderStyle.BackColor = gridbackcolor
> clBT.HeaderStyle.ForeColor = gridforecolor
> clBT.HeaderStyle.Font.Name = "Arial"
> clBT.HeaderStyle.Font.Bold = True
> clBT.HeaderStyle.Font.Size = fontsize
> clBT.Text = "delete"
> clBT.ItemStyle.Font.Size = 8
> clBT.ItemStyle.Font.Name = "Arial"
> clBT.ItemStyle.Font.Underline = True
> clBT.ButtonType = ButtonType.Link
> clBT.ItemStyle.Width = 40
> clBT.ItemStyle.HorizontalAlign = HorizontalAlign.Center
> ctrl.Columns.Add(clBT)
>
> where ctrl is the gridview.
> This is the 14th column.
>
> The following is in the RowDatabound event:
>
> If e.Row.RowType = DataControlRowType.DataRow Then
> If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState =
> DataControlRowState.Alternate Then
> Try
> If e.Row.Cells(14).Controls.Count > 0 Then
> Dim lb As LinkButton = e.Row.Cells(14).Controls(0)
> lb.Attributes.Add("onclick", "javascript:return confirm('Are you
> sure?')")
> End If
> Catch ex As Exception
> End Try
> End If
> End If
>
> What can I do now?
>
> rg,
> Eric

I think I solved it now, after a click on OK the rowcommand event is fired,
but with cancel it isn't.
So can use that since I don't use it for anything else.

Not sure if it is the right solution, though.

rg.
Eric