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

Need to call client side method to open window from codebehind

2 Answers 105 Views
Window
This is a migrated thread and some comments may be shown as answers.
fred williams
Top achievements
Rank 1
fred williams asked on 12 Nov 2010, 05:34 PM
I created two radwindows which i'd like to serve as result alerts after a user tries to upload files to a database. they select the files, then click an upload button.

What I'd like to do is open either the 'success' radwindow or the 'fail' radwindow based on whether or not the upload was successful. I tried using client script manager in codebehind to open the windows but it isn't working.
int result = cmd.ExecuteNonQuery();
if (result < 1)
{
    
    String strFail = "<script type=text/javascript> var oWnd = radopen(null, 'fail');</script>";
    ClientScriptManager sm = Page.ClientScript;
    sm.RegisterStartupScript(this.GetType(), "upFail", strFail);
}
else
{
   
    String strSuccess = "<script type=text/javascript> var oWnd = radopen(null, 'success');</script>";
    ClientScriptManager sm = Page.ClientScript;
    sm.RegisterStartupScript(this.GetType(), "upSuccess", strSuccess);

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Tunev
Telerik team
answered on 17 Nov 2010, 10:48 AM
Hello Fred,

Note that RegisterStartupScript() will put the <script> block just before the closing </form> tag and the code in the function will be executed in window.onload - i.e. when the page is loaded. All ASP.NET AJAX controls however (including ours), are registered on the page on a later stage - in Sys.Application.Load - you can easily verify that by putting ASP.NET AJAX controls on a page and examining the HTML dump once the page is loaded in the browser. Basically, what happens is that your code is outputted and executed on the page, before the Ajax controls are rendered, which causes the error.

To summarize, for your code to work, you need to execute it on a later stage. Please check this blog post for more information on the subject and several suggested approaches. If you still experience problems after that, please provide a sample project where I can examine your exact setup. I am asking this because as you will see in the blog, the approaches differ, depending on the setup and logic.



Best wishes,
Georgi Tunev
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
fred williams
Top achievements
Rank 1
answered on 24 Nov 2010, 07:58 PM
I was able to get it to run by adding Sys.Application.remove_load() and add_load to my code:
String strSuccess = "<script type=text/javascript> function f(){ radopen('Success.aspx', 'success');Sys.Application.remove_load(f);}Sys.Application.add_load(f);</script>";
ClientScriptManager sm = Page.ClientScript;
sm.RegisterStartupScript(this.GetType(), "upSuccess", strSuccess);
cboFiles.OpenDropDownOnLoad = false;
Thanks for you help!
Tags
Window
Asked by
fred williams
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
fred williams
Top achievements
Rank 1
Share this question
or