This is a migrated thread and some comments may be shown as answers.

Open Rad Confirm and alert dialogs from server side code

3 Answers 432 Views
Window
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 1
Guy asked on 10 Jun 2009, 09:39 AM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Svetlina Anati
Telerik team
answered on 10 Jun 2009, 10:24 AM

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.
0
Shinu
Top achievements
Rank 2
answered on 10 Jun 2009, 10:34 AM
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.
0
Guy
Top achievements
Rank 1
answered on 10 Jun 2009, 11:07 AM
Many thanks, this works pefectly.
Tags
Window
Asked by
Guy
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Shinu
Top achievements
Rank 2
Guy
Top achievements
Rank 1
Share this question
or