Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Nickel Contributor
Posts: 93
Registered: ‎01-02-2010

Carriage Return in ShowMessage

I want to display a multi-line message to users when a button on a form is clicked.

 

At the moment, I've got something like this:

 

 

           string sHelpText = "Line 1";
            sHelpText = sHelpText + "\n" + "Line 2";
          
            IWebDialogService dialog = form.Services.Get<IWebDialogService>();
            dialog.ShowMessage(sHelpText);

 

 

where "\n" is (I believe) the C# equivalent of vbCRLF.

 

But when the message displays, the \n appears to be displayed as a single space character (only). No new line is thrown.

 

I also tried System.Environment.NewLine - same result.

 

Any ideas what I need to do to get my lines separated as I want them?

 

Thanks in advance.

Highlighted
Nickel Contributor
Posts: 59
Registered: ‎07-30-2010

Re: Carriage Return in ShowMessage

Hello PhilP,

 

I will admit i've not tried it in the context you want to use it in, but "\r\n" should work.

 

Thanks,

Richard Anderson
CRM Consultant
K3 CRM
Highlighted
Bronze Super Contributor
Posts: 236
Registered: ‎03-30-2009

Re: Carriage Return in ShowMessage

Try this - it uses an HTML break:

 

string sNewLine = "<" + "br" + "/" + ">";

 

Just insert the string 'sNewLine' anywhere you want a newline in the messge.  I use this all the time for jscript alert boxes and exception alerts.

Mike LaSpina
Professional Services Consultant

Sage
8800 N Gainey Center Dr Ste 200
Scottsdale AZ 85258
Tel: 480-383-5344
Cell: 480-321-6637
Fax: 480-556-4090
mike.laspina@sage.com

Your Business in Mind.
Highlighted
Nickel Contributor
Posts: 93
Registered: ‎01-02-2010

Re: Carriage Return in ShowMessage

Neither of these methods works, I'm afraid.

 

"\r\n" has the same effect as "\n".

 

"<" + "br" + "/" + ">" is faithfully rendered as "<" + "br" + "/" + ">" when the message is displayed Man Happy

 

 

Highlighted
Bronze Super Contributor
Posts: 236
Registered: ‎03-30-2009

Re: Carriage Return in ShowMessage

Looks like the DialogService.ShowMessage is doing some encoding thus overriding your desired behavior.  This, and the lack of an 'OK' button on the dialog is why I use JScript alerts instead:

 

    string sNewLine = "\\n";
    string sAlert = "alert('This is line 1" + sNewLine + "This is line 2');";
    ScriptManager.RegisterStartupScript(Page, GetType(), "Message", sAlert, true);

 

Note that the original technique I mentioned does work if you're throwing a Validation Exception - which calls the Ext-js alert box rather than the stock alert function.

 

Keep in mind that you may need to re-work that last line of code if you're calling this from a from snippet.  My example is an in-line snippet which is marked as Obsolete in AA.

Mike LaSpina
Professional Services Consultant

Sage
8800 N Gainey Center Dr Ste 200
Scottsdale AZ 85258
Tel: 480-383-5344
Cell: 480-321-6637
Fax: 480-556-4090
mike.laspina@sage.com

Your Business in Mind.
Highlighted
Nickel Contributor
Posts: 93
Registered: ‎01-02-2010

Re: Carriage Return in ShowMessage

[ Edited ]

Here's what I ended up doing.

 

1) Create Link controls on the form.

2) Modify the OnLoad event for the form to assign the destination property of the link controls appropriately...

 

 

"javascript<colon>alert('" + sHelpText + "')";

 using

 

 

 

string sNewLine = "\\r\\n";

 

 

as the new-line directive within the destination text (sHelpText)..

Highlighted
Nickel Contributor
Posts: 57
Registered: ‎03-18-2010

Re: Carriage Return in ShowMessage

Hi,

 

I get the same problem since SP3.

To avoid this problem, I created a custom smartpart with a literal control.

I used a module to load this control on each page.

 

Now I call my dialog like this:

 

        this.DialogService.DialogParameters.Clear();
        this.DialogService.DialogParameters.Add("Text", myText);
        this.DialogService.SetSpecs(400, 600, "myDialog", "myTitle");
        this.DialogService.ShowDialog();

 

 

Libert Damien