RadWindow ALERT From Code Behind NOT WORKING

6 posts, 0 answers
  1. Shawn
    Shawn avatar
    83 posts
    Member since:
    Jan 2009

    Posted 23 Jan 2009 Link to this post

    I am trying to set a simple function that will display my message in a RadWindow alert box.  I assumed it was a two step process

    1) - Place RadAjaxManager on page
    2) - Call it in your code behind like so:
    Private Sub DisplayMessage(ByVal text As String
            RadAjaxManager1.ResponseScripts.Add("radalert('" & [text] & "', 330, 210);"
        End Sub 

    This does not work - I get a Javascript error from the object.

    Is there a better way?
  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 23 Jan 2009 Link to this post

    Hello Shawn,

    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 as shown below:

    protected void Button1_Click(object sender, EventArgs e)     
        {     
            RadAjaxManager1.ResponseScripts.Add(@"Sys.Application.add_load(function()  
            {radalert('Welcome to RadWindow for <b>ASP.NET AJAX</b>!', 330, 210);})");     
        }    
     
     

    You can find additional information about this here.

    Regards,

    Svetlina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Shawn
    Shawn avatar
    83 posts
    Member since:
    Jan 2009

    Posted 23 Jan 2009 Link to this post

    Ahhhh, that's it - thank you!

    How do I put a title on the radWindow though?
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 26 Jan 2009 Link to this post

    Hello Shawn,

    The title of the radalert dialog is the last argument in the radalert() function.
    e.g.:
    radalert('Welcome to RadWindow for <b>ASP.NET AJAX</b>!', 330, 210,'My Title');


    Best wishes,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Eric
    Eric avatar
    20 posts
    Member since:
    Jul 2008

    Posted 08 Apr 2009 Link to this post

    I have tried this code but I still do not get the window to pop.  The
     Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click  
            If Not CheckForUser() Then  
                RadAjaxManager1.Alert("No users are selected!")  
                RadAjaxManager1.ResponseScripts.Add("Sys.Application.add_load(function()    " & vbCr & vbLf & "        {radalert('Welcome to RadWindow for <b>ASP.NET AJAX</b>!', 330, 210);})")  
            End If  
        End Sub 
    the Alert works perfect and I guess it will work, but I was hoping to have the window appear diffent to attract the users attention more.  Is there some secret. I am using RadAjaxManager and RadWinindowsManager.
  6. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 09 Apr 2009 Link to this post

    Hi Eric,

    The code seems fine so at this point I cannot tell what the reason for the problem might be.
    I would suggest to check the following KB article that shows how to call radalert in different scenarios - I hope it will be of help.
    http://www.telerik.com/support/kb/aspnet-ajax/window/calling-radalert-from-codebehind.aspx

    If you still experience problems after that, please open a support ticket and send me a sample page where I could examine your exact setup. Once I have a better view over your case, I will provide you with the appropriate solution.

    Best wishes,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top