Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2014, 04:50 PM
Authorized User
 
Join Date: Aug 2011
Posts: 44
Thanks: 14
Thanked 0 Times in 0 Posts
Default Chapter 13 - Genre GridView

Hello Imar,

in the Genre GridView (chapter 13) I added the following property to the Delete button (which I had converted from a CommandField to an ItemTemplate):

Code:
OnClientClick="return confirm('Do you really want to delete the selected genre ?');"
in order to prevent unintentional deletes.

It works, but I would like to refine it.
I would like to concatenate the name of the genre selected so that the message to the user turns, for instance, into:
'Do you really want to delete the Hard Rock genre ?'

I'm trying to do that by means of a Javascript function, but I got an error at

Code:
document.getElementById('<%= labelGenreName.ClientId%>')
Therefore I cannot reach the Label whose value is the name of the genre.
By the way, the label is into an ItemTemplate, as I converted the original BoundField into a Template.

Can you tell me how to concatenate the name of the genre into the message ?

Thank you

Last edited by Antonius Block; January 7th, 2014 at 04:52 PM..
 
Old January 7th, 2014, 05:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Antonius,

One way to do it is using databinding:

Code:
OnClientClick=<%# String.Format("return confirm('Do you really want to delete the {0} genre?');", Eval("Name")) %>
Notice that the entire data binding expression doesn't use quotes. If you'd use single or double quotes, the strings in the expression would break the tag.

This is a bit messy, so you could also do it from Code Behind as explained here: http://stackoverflow.com/a/102479/1498619

With you solution, you run into issues, as each label for each row will have a unique ID. Take a look at the HTML in the browser to see what I mean. You could pass the name to the function to make things a lot easier:

Code:
OnClientClick=<%# String.Format("confirmDelete('{0}');", Eval("Name")) %>
where confirmDelete is your custom confirmation function that accepts the genre name.

Finally, you could also use jQuery to do all this dynamically. You could find sibling table cells that contain the genre name to create the proper prompt.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Antonius Block (January 7th, 2014)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch. 15 - AddEditReview page & preselecting genre on Insert? Tulsi BOOK: Beginning ASP.NET 4 : in C# and VB 6 February 5th, 2013 03:20 PM
single review for every genre sophia BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 October 24th, 2012 06:46 PM
Chapter 13: Not seeing "Edit Columns" choice in SmartTasks Panel for Gridview wgrayson BOOK: Beginning ASP.NET 4 : in C# and VB 7 August 27th, 2012 04:30 AM
CH 17 Storing Genre Preferences in the Profile - Error! leeWozyWarren BOOK: Beginning ASP.NET 4 : in C# and VB 3 December 7th, 2011 01:20 PM
Genre and Show objects association vyurik BOOK: Professional Java Development with the Spring Framework 0 July 6th, 2006 06:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.