Allowed content for RADAlert?

5 posts, 0 answers
  1. Matt
    Matt avatar
    29 posts
    Member since:
    Oct 2011

    Posted 21 Nov 2011 Link to this post

    I'm trying to use RadAlert in my .Net 4.0 web form/app and have found that trying to display certain text makes the window fail to appear.
    I was trying to put a html table in mine and when I do the alert doesn't ever show up when called. Using the same code I can make the window display with no html tags involved. From what I have read html should be allowed, right?

    If my message is "Testing 123" the window pops up.

    If my message is a html table, the window doesn't pop up, like this:
    "<table>
        <tr>
            <td>
                Label:
            </td>
            <td>
                Value
            </td>
        </tr>
    </table>"

    But a simpler html snippet like this does pop up:
    Label:   <i>value</i> <br />

    Is there a resource that will show me exactly what is or isn't allowed? Or is it a length restriction? Thanks!
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 22 Nov 2011 Link to this post

    Hello Matt,

    I don't see an issue with passing html content into the radalert method. I'm calling it like so:

    radalert("<table><tr><td>Label:</td><td>Value</td></tr></table>");

    Does that not work for you?

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 22 Nov 2011 Link to this post

    Hello Matt,

    I also tried this code and things worked as expected with me: http://screencast.com/t/lzkkY42UG. I am also attaching my test page here. Can you reproduce this behavior with it?

    I would also ask you to confirm there isn't a JavaScript error before the RadAlert is called, as this would prevent it from executing.

    Are you also using the quote marks? Since this content needs to be handled via JavaScript you may need to escape symbols with special meaning for this language - quotes (single or double) as they are a string delimiter, backslashes, etc.

    Generally the RadAlert supports HTML strings, the only peculiarity is that this string passes through JavaScript so it needs to be properly escaped and delimited.

    As for the length - it can take much longer messages than this and the length is practically not limited.


    Greetings,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  5. Matt
    Matt avatar
    29 posts
    Member since:
    Oct 2011

    Posted 29 Nov 2011 Link to this post

    Thanks for the reply and sorry I took so long to get back.

    I'm calling this alert from codebehind triggered by events from RadScheduler like this:

        private void ShowPopUp(string heading, string message)
        {
            string radalertscript = "<script language='javascript'>function f(){radalert('" + "<p><h2>" + heading + "</h2></p>" + message + "', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
        }

    Could the way I'm approaching this be the cause of my problems? I read this:
    http://www.telerik.com/help/aspnet/window/callingradalertfromcodebehind.html

    Which says: "The task gets complicated if Ajax is used because the page does not reload and window.onload is fired only once (when the page is initially shown). When using Ajax you must apply an appropriate solution depending on the exact case."

    So I think I may have hit that complicated scenario because RadScheduler is using Ajax and my page doesn't do postbacks. Got any suggestions? I just wanted a simple way to pop up a dialog with html in it to display to the user.
    Thanks!
  6. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 30 Nov 2011 Link to this post

    Hello Matt,

    If your using the RadAjaxManager or RadAjaxPanel, you use this to show the radalert:

    string radAlertScript = ("radalert('" + "<p><h2>" + heading + "</h2></p>" + message + "', 330, 210);";
    RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(radAlertScript);

    You can just add it the javascript call to the ResponseScripts collection of the RadAjaxManager or RadAjaxPanel control.

    I hope that helps.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017