Need to call client side method to open window from codebehind

3 posts, 1 answers
  1. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 12 Nov 2010 Link to this post

    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. Answer
    Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 17 Nov 2010 Link to this post

    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.
  3. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 24 Nov 2010 Link to this post

    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!
Back to Top