Monday, March 26, 2012

ConfirmButtonExtender + Text Formatting

Hi!

I often need to have some quite long confirmation messages for user actions, and would normally achieve this by formatting theConfirmText string using\t and\n in my javascript to achieve this. For example,

confirm('Are you sure you want to do this?\n\nThe consequences of this action are:\n\t1) xxx\n\t2) yyy')

When using this sort of technique with the ConfirmButtonExtender, the \n and \t areescaped and rendered as is!

Is there any way to add put this control characters into the text??

Thanks,

James

Have you tried changing ConfirmButton.js's this._onClick method to unescape the string before displaying it? (Perhaps with JavaScript's regex functionality?)

Hi David,

No I haven't tried that, but to be honest, it's not really a route I want to go down... while it would work perfectly well, I don't think that it is something that I can rely upon for future versions of the toolkit...

If this is considered a bug that will be fixed in future versions, then it's worth making the change, but if not, I will be stuck with a solution that could have a limited lifespan once we no longer have access to the .js files!Big Smile [:D]

Cheers,

James


As far is I know, the Toolkit and its source will always remain free to users. I'd say that you should feel free to make changes like this. I'm undecided on whether or not to declare this a bug in the Toolkit. I'm a little afraid of getting into escaping here if it's not something that lots of people will want (I'm considering the added complexity vs. the value). If I hear from a few others that unescaping is desired (feel free to reply to this post), I'll log a bug to fix this. Thanks!
Thanks for this David... here's my view on it:

1) Anyone currently trying to do a confirm box without the toolkit would expect to escape their strings as they would be using Javascript... Surely the extender should allow you to achieve this same functionality out of the box?!Idea [Idea]

2) Isn't the purpose of the Toolkit to make life easier... not more difficult!!!Smile [:)]

3) As soon as someone needs to have a long string to display it is going to look pretty ugly without some formatting

4) I'm sure that this isn't going to be the only release of the toolkit... I personally don't want to be having to patch the toolkit every time a new version is released... and my boss wouldn't be happy using technology that requires a manual patch every time either... and it doesn't look great telling other developers in the department that in order to maintain my source code they have to download a toolkit and make changes to it straight away!!

5) If the toolkit ends up being like the rest of Atlas, the .js files will eventually get packaged up and not available for editing. Although you will be more in the know than I am, I'm just being realistic!!Wink [;)]

Just my opinion, but I would really appreciate it if this was considered a bug!!

I would much prefer to use the toolkit as it seems the right way to go from a design point of view, but having to make changes to it is less attractive than adding

OnClientClick="return confirm('Text\n\nMore Text');"
Regards,

James
Okay, you win. :) I've added a note to try to address this in the next release. Thanks for the follow-up!

We discussed this issue at some length just now. There were a couple of different viewpoints, but ultimately we all agreed on a solution we like.

The problem with modifying the .js behavior itself (as I was initially planning to do) is that we introduce JavaScript/C# conventions ('\n' -> new line) into a .ASPX page that may be written in VB (or some other language). This could be confusing for page authors. Additionally, we'd have to choose exactly what escapes to support and that choice could be kind of arbitrary.

Instead, the proposal was to let the page author make the necessary change in the language of their choice by having them modify the OnLoad member of their page to override the ConfirmText property of the relevant ConfirmButton control(s). It's not quite as seamless, but it has the benefits that a) it works in the page's programming language, b) you can make the change with the current release, and c) you never need to make the change again even as we release new Toolkits. Sounds good, huh?

An example of this technique in action:

I added the following to ConfirmButton.aspx.cs to add the appropriate new line characters:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ConfirmButtonExtender1.GetTargetProperties(Button1).ConfirmText = "Are you sure you want to do this?\n\nReally sure?";
}

And, to avoid confusion, changed ConfirmButton.aspx from:

<atlasToolkit:ConfirmButtonProperties TargetControlID="Button1" ConfirmText="Do you have any idea what this button does?" />

To:

<atlasToolkit:ConfirmButtonProperties TargetControlID="Button1" ConfirmText='[Set by ConfirmButton_ConfirmButton.OnLoad]' />

That's it! The result is a confirm dialog with new line characters just like you'd expect. Hope you like it!!


Hi David,

Thanks for this, however I'm still having problems with implementing this in my situation:

I have myButton andConfirmButtonExtenderembedded deep within aEditItemTemplate within aTemplateFieldin aGridViewinside aWizard!!
I hear you. I'm running another idea by folks to see if they like that any better...

James,

I think I've got something you'll like: HTML Entities! If you're not familiar, you can see a little chart here:http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/charsets/charset1.asp. Of particular interest to us in this case is " ", decimal value 10, which corresponds to the '\n' character. Changing the sample string to "Do you have any idea what this button does? Really??" results in a confirm dialog with a blank line just like you want. The great thing about this approach is that it encodes the formatting in the language of the ASPX page itself, HTML, and maintains all of the code/content separation you were asking for. Additionally, it requires no changes to the ConfirmButton extender which is always nice for me. :)

Hope you like it!

PS - " " is tab.


That's fantastic!! Thank you very much David... exactly what I've been looking for (but should really have known it I guess!!).

Regards,

James

Love your work and suggestion.

However when I use this approach to put the text in the Confirm text section with my vb.net code it didn't work.

Do you have any idea what this button does? Really??

It apprears as it is no

Do you have any idea what this button does? Really??

I am not sure what I am doing wrong?

Also when I havce more than one button on my Web Form Each button require a confirm text how to have it it only for the specific button not for every button on the form.

Thanks
Tanweer


Are you putting the " " entities in the .ASPX page (not the code-behind .ASPX.VB file)? If so, please post a small, simple demonstration of the problem. Thanks.

I am putting it in the Properties window of the confirmation text part where I put my message.

Thanks
Tanweer


Just to let you know in Html hat code is working ok.

However when I use it in the Properties window of ConfirmButtonExtende ConfirmText and type the text with it does not transalate to \n.

I am using Vb.Net

Also I haven't got any naswer how to turn off this Confirmatin box for other Buttons in the form.

Thanks
Tanweer

No comments:

Post a Comment