Solved

javascript popup question

Posted on 2006-11-27
13
372 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now