Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript popup question

Posted on 2006-11-27
13
Medium Priority
?
391 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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