Open Rad Confirm and alert dialogs from server side code

4 posts, 1 answers
  1. Guy
    Guy avatar
    49 posts
    Member since:
    Oct 2007

    Posted 10 Jun 2009 Link to this post

    Hi,

    I am rolling out a consistent set of alert dialogs and controls across our systems and part of this task is to get rid of old error/informational messages and replace them with something better.

    i like the radwindow alert and confirm dialogs and want to embed them in our existing codebase.

    What we currently have is a method in our basepage called showAlert..

    protected void ShowAlert(string msg) 
    var myScript = string.format("alert('{0}');",msg); 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "SCR", myScript, true); 

    This just makes a basic javascript alert popup once the postback has finished and alerts the user.

    I want to replace this with the radWindowManager and use the built in alerts.

    How can i initiate the alert and confirm dialogs from the server side?  there seems to be no examples available.

    I tried adding a radwindowManager to my page, then i modified the ShowAlert() method like so....

            protected void ShowAlert(string msg) 
            { 
                string myScript = string.Format("radalert('A string.', 200, 100,'{0}');", msg); 
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SCR", myScript, true); 
            } 
     


    but i get the following error...

    _5 is undefined
    radalert()("A string.", 200, 100, "hello")ScriptRe...=53f5b61a (line 8)
    default.aspx()()default.aspx (line 135)
    var _6=_5._getStandardPopup("alert",_1);

    What am i doing wrong here?
  2. Answer
    Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 10 Jun 2009 Link to this post

    Hi Guy,

    The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls (including RadWindowManager) in the Sys.Application.add_init() method.

    Here is how the client events are fired in the page life cycle:

    window.onload -> Sys.Application.init -> Sys.Application.load

    You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.

    That is why when you call your code in window.onload by registering the client script, the RadWindowManager will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.

    This being said, please try the following syntax:

    protected void ShowAlert(string msg)    
            {    
                string myScript = string.Format("Sys.Application.add_load(function(){radalert('A string.', 200, 100,'{0}');})", msg);    
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SCR", myScript, true);    
            }    
     

    I believe that the following KB article will also be helpful:

    http://www.telerik.com/support/kb/aspnet-ajax/window/calling-radalert-from-codebehind.aspx


    Regards,

    Svetlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2009 Link to this post

    Hi Guy,

    RadControls for ASP.NET AJAX, being MS AJAX objects, are rendered after page is loaded. You need to add a Sys.Application.Load handler in order to ensure that RadWindowManager is already rendered on the page. Try the following code for showing RadAlert from code behind.

    CS:
     
    string radalertscript = "<script language='javascript'>function f(){radalert('A string', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";  
    Page.ClientScript.RegisterStartupScript(this.GetType(), "SCR", radalertscript);  
    Check out the following KB article for more information:
    Calling radalert from codebehind (all versions of RadWindow)

    Thanks,
    Shinu.
  5. Guy
    Guy avatar
    49 posts
    Member since:
    Oct 2007

    Posted 10 Jun 2009 Link to this post

    Many thanks, this works pefectly.
Back to Top