Solved

javascript popup question

Posted on 2006-11-27
13
377 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET website keeps me current? 9 52
ASP.NET reading ATOM 2 51
Re-position the objects 7 95
c# LinkButton OnClientClick 2 33
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now