?
Solved

javascript popup question

Posted on 2006-11-27
13
Medium Priority
?
388 Views
Last Modified: 2008-01-09
this is just a simple question about making a popup confirmation window. i have a gridview and a custom button field that's essentially an image that's linked to another page with a parameter and the button just deletes the record and all associated records. i needed to do it this way because there are associated records in other tables that have to be deleted as well, so it was just easer to do it all on another page and redirect back. so it goes like this ->

gridview supplies the ID parameter to the link
<a href='remove.aspx?delay=<%#Container.DataItem("ID")%>' title="Delete This Delay"><img src="images/remove.gif" border="0"/></a>

then remove.aspx deletes the delay and its associated records in other tables and redirects back to the original page.

what i want to do is just throw up a simple popup that says "are you sure you want to delete this delay?" and clicking yes follows the link, clicking no cancels the link-click. i know absolutely nothing about javascript, but i'm assuming it'd be the easiest way to do this?
0
Comment
Question by:craskin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 1500 total points
ID: 18020226
Hi craskin,

<a onclick="if(window.confirm('are you sure you want to delete this delay?') window.location.href=remove.aspx?delay=<%#Container.DataItem("ID")%>;" title="Delete This Delay"><img src="images/remove.gif" border="0"/></a>


Tim Cottee
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18020234
craskin,

<a onclick="if(window.confirm('are you sure you want to delete this delay?') window.location.href=remove.aspx?delay=<%#Container.DataItem("ID")%>; else return false;" title="Delete This Delay"><img src="images/remove.gif" border="0"/></a>

Slightly better perhaps.


Tim
0
 
LVL 7

Expert Comment

by:whityum
ID: 18020249
I would do something like this:

page:
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" CssClass="adminButton"
Text="delete" OnClientClick="return confirm('Permanantly delete this company?')" />

code behind:
protected void btnDelete_Click(object sender, EventArgs e)
{
             //delete function
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:ethoths
ID: 18020335
Or you could use a custom validator. Essentialy it's the same as the solutions listed above but it wrapped in a neater solution.
0
 
LVL 12

Author Comment

by:craskin
ID: 18020409
TimCottee, i tried your onclick and it made the image unlcickable.
0
 
LVL 7

Expert Comment

by:whityum
ID: 18020423
for my example, you could use an image button and give it a source attribute to make it an image
0
 
LVL 12

Author Comment

by:craskin
ID: 18020471
whity, how would i send the id to the delete function in a simple way?

in my remove page, i just do

        Dim DelayID As Integer = CInt(Request.Params("delay"))
        Tractime.DeleteDelay(DelayID)
        Tractime.UnApplyDelay(DelayID)
        Response.Redirect(Request.UrlReferrer.ToString)

all i would have to change is the first line to assign DelayID properly, but i need to know how to send it from the imagebutton.
0
 
LVL 7

Expert Comment

by:whityum
ID: 18020639
give it a command argument

<asp:ImageButton ID="btnDelete" runat="server" OnClick="btnDelete_Click" CssClass="adminButton"
Text="delete" OnClientClick="return confirm('Permanantly delete this company?')" CommandArgument='<%#Container.DataItem("ID")%>' />

protected void btnDelete_Click(object sender, CommandEventArgs e)
{
             //delete function
ID = CInt(e.CommandArgument)
}
0
 
LVL 12

Author Comment

by:craskin
ID: 18020683
whityum,

that seems to not be allowed since imagebuttons must use imagebuttoneventargs and commandargument is not a member of that handler.
0
 
LVL 12

Author Comment

by:craskin
ID: 18020691
i have

    Sub btnDelete_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim DelayID As Integer = CInt(e.CommandArgument)
        Tractime.DeleteDelay(DelayID)
        Tractime.UnApplyDelay(DelayID)
        Response.Redirect(Request.UrlReferrer.ToString)
    End Sub

and i get

BC30456: 'CommandArgument' is not a member of 'System.Web.UI.ImageClickEventArgs'.

so i try CommandEventArgs

and i get

BC30408: Method 'Public Sub btnDelete_Click(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)' does not have the same signature as delegate 'Delegate Sub ImageClickEventHandler(sender As Object, e As System.Web.UI.ImageClickEventArgs)'.


0
 
LVL 7

Expert Comment

by:whityum
ID: 18021211
use command event args like I have in my example.
0
 
LVL 12

Author Comment

by:craskin
ID: 18021408
i did that and that's when i got the second error

BC30408: Method 'Public Sub btnDelete_Click(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)' does not have the same signature as delegate 'Delegate Sub ImageClickEventHandler(sender As Object, e As System.Web.UI.ImageClickEventArgs)'.
0
 
LVL 12

Author Comment

by:craskin
ID: 18022141
well i got the javascript onclick to work and it was the simplest approach

<a onclick="return confirm('Are you sure you want to delete?')" href='remove.aspx?delay=<%#Container.DataItem("ID")%>' title="Delete This Delay"><img src="images/remove.gif" border="0"/></a>

points to Tim for pointing me in the right direction.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question