Solved

javascript popup question

Posted on 2006-11-27
13
386 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 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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