New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAdd a confirmation to delete button in a gridAdd a confirmation to delete button in a grid
Previous
 
Next
New Post
1/23/2013 1:58 PM
 

Hi,

I want to add a confirmation to a delete button in a GridView.

In the Grid_ItemDataBound event, I normally use something like

ImageButton delBtn = (ImageButton)e.Item.FindControl("DeleteBtn");
delBtn.OnClientClick = String.Format("return confirm('Are you sure you want to delete {0}');", ((DateRowView)e.Item.DataItem)["Name"]);

When I want to do this using the dnnConfirm function I run into errors. Can anyone advise me how to do it?

Note: The confirm message should be different for every row by containing the "Name" field value.

Thanks for any help...

Best wishes
Michael

 


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
1/23/2013 2:21 PM
 
So what did you actually try?

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
1/23/2013 9:32 PM
 
We currently sucessfully use the dnnConfirm in our project, however, we only to find that dnnConfirm is only applicable for LinkButton or a.

NovaSoftware ---a professional outsourcing company in China .
* More than 6 years' offshore experience in DNN
* Successfully developed 30+ websites , 250+ DNN modules, 50+ sets of Skins/Containers.
* Demo Site:http://dotnetnuke.novasoftware.com/
 
New Post
1/24/2013 2:43 AM
 
Richard Howells wrote:
So what did you actually try?

Richard,

thanks for your interest.

Well, first I tried some stuff that looked like the other thing, but it did not work.

I then tried to assign a common error message. I assigned CssClass="confirm" to all of the buttons and injected a script in the Page_Init event like

StringBuilder script = new StringBuilder();
script.Append("jQuery(function($) { $('.confirm').dnnConfirm( { text: '");
script.Append(Localization.GetSring("DeleteItem.Text"));
script.Append("', yesText: '");
script.Append(Localization.GetSring("Yes.Text"));
script.Append("', noText: '");
script.Append(Localization.GetSring("No.Text"));
script.Append("', title: '");
script.Append(Localization.GetString("Confirm.Text");
script.Append("', dialogClass: 'dnnFormPopup', isButton: true });})");
if (!(base.ClientScript.IsClientScriptBlockRegistered("ConfirmDeleteScript")))
base.ClientScript.RegisterClientScriptBlock(this.GetType(), "ConfirmDeleteScript", script.ToString(), true);

That worked fine.

Then I commented this out and went back to the Grid_ItemDataBound Event. There I did something like this:

ImageButton delBtn = (ImageButton)e.Item.FindControl("DeleteBtn");
StringBuilder script = new StringBuilder();
script.Append("jQuery(function($) { $().dnnConfirm( { text: '");
script.Append(String.Format(Localization.GetSring("ConfirmDelete.Text", base.LocalResourceFile), ((DateRowView)e.Item.DataItem)["Name"]));
script.Append("', yesText: '");
script.Append(Localization.GetSring("Yes.Text"));
script.Append("', noText: '");
script.Append(Localization.GetSring("No.Text"));
script.Append("', title: '");
script.Append(Localization.GetString("Confirm.Text");
script.Append("', dialogClass: 'dnnFormPopup', isButton: true });})");
delBtn.OnClientClick = script.ToString();

When I click to that, I run into an error. The script looks fine except that all the single quotes are HTML-encoded and therefore the script is unusable. No confirm dialog, the item gets deleted as the program execution is continued.

Any idea?

Best wishes
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
1/24/2013 5:57 AM
 

Hi Michael,

I think the HTML encoding of the quotes can be ignored.  I have seen this before and it just seems to work fine.

I'm no jQuery expert, but I think jQuery is not intended to be used that way.  I think the general approach would be:

- write a single function that will create the confirmation.  This function needs to be sufficiently general that when called for ANY of your Delete buttons it can find the extra data that goes in the confirm dialog.  You might use the jQuery metadata plugin as a way of smuggling that data into the grid, or maybe you can get it from some other control on the page.

- from the jQuery ready event, attach that function to all the Delete buttons on the page.

I'm not 100% sure but I think your current code has a problem because in the client onclick event you are attaching another jQuery ready event.  That feels too late to me.

HTH.


Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAdd a confirmation to delete button in a gridAdd a confirmation to delete button in a grid


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.