RadWindow close on server side

10 posts, 0 answers
  1. drpcken
    drpcken avatar
    36 posts
    Member since:
    Feb 2007

    Posted 28 Apr 2009 Link to this post

    I have a page with a RadWindow.  The page that loads in the radwindow is a login form.  Basically when teh Login button is pressed an integer is returned based on if the credentials are successfull or not.  If the integer is 0, it simply lets them know they have the wrong password, this is already setup and works.  However if the returned integer is 1, i want it to close the radwindow, run some serverside code based on a value passed from the RadWindow (ie the Users primary key) and redirect the parent page to another page.  Here is my server side code for the login page:
    protected void submitbutton_Click(object sender, EventArgs e) 
        { 
            //checks credentials, returns 1 or 0 
            int authStatus = Authentication.AuthenticateEmployee(txtUsername.Text.Trim(), 
                Encryption.encryptStringSHA256(txtPassword.Text.Trim())); 
     
            switch (authStatus) 
            { 
                case 0: 
                    lblStatus.Text = "code0: Your user does not have access"
                    break
     
                case 1: 
                    lblStatus.Text = "code1: Successfull"
                    //here i want it to close the radwindow and run some server side code. 
                    break
            } 
             
             
     
     
        }
    I know how to pass values from the radwindow to the parent page, but I'm not sure how to access those values server side.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Apr 2009 Link to this post

    Hi,

    Try the following code snippet.

    CS:
     
    protected void submitbutton_Click(object sender, EventArgs e)   
    {  
          . . .   
        switch (authStatus)   
        {   
            case 0:   
                lblStatus.Text = "code0: Your user does not have access";   
                break;  
            case 1:  
                lblStatus.Text = "code1: Successfull";   
                // some server side code.  
                string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(CloseAndRedirect);</script>";  
                ClientScript.RegisterStartupScript(this.GetType(), "Close", script);   
                break;   
        }  

    JavaScript:
     
     
    <script type="text/javascript">       
    function CloseAndRedirect(sender, args)       
    {           
        GetRadWindow().BrowserWindow.location.href = 'loggedIn.aspx';        //Redirect to new url 
        GetRadWindow().close();       //closes the window       
    }       
    function GetRadWindow()   //Get reference to window    
    {       
        var oWindow = null;       
        if (window.radWindow)       
             oWindow = window.radWindow;       
        else if (window.frameElement.radWindow)       
             oWindow = window.frameElement.radWindow;       
        return oWindow;       
    }       
    </script>    

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. drpcken
    drpcken avatar
    36 posts
    Member since:
    Feb 2007

    Posted 29 Apr 2009 Link to this post

    Thanks for the help but that code isn't working.  I pasted it exactly as you put it.  It successfully authenticated but it doesn't close the window and redirect the parent page.

    Any idea why?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Apr 2009 Link to this post

    Hello,

    The code is working fine in my end (with RadControls version 2009.01.0311.35). Can you put break point and see whether the client side function is executing or not?
    Checkout the code library which demonstrates how RadWindow can be used for a login form which will redirect the parent page to a specific URL after a successful login.
    Using r.a.d.window for a login form

    Thanks,
    Shinu.
  6. Michael
    Michael avatar
    1 posts
    Member since:
    May 2009

    Posted 14 Jan 2010 Link to this post

    I know this is an older post but I had trouble with the example as well. I got it to work with the following:

    string 
    script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(CloseWindow);</script>";  
    RadScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", script, false);
    Since I am using the RadScript manager, I needed to register the script with it instead of the normal script manager. I think that is why it works.
  7. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 14 Jan 2010 Link to this post

    Hello Drpcken,

    I believe that the "Calling radalert from codebehind" KB article will be of help.

    Greetings,
    Fiko
    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.
  8. Pei Chen
    Pei Chen avatar
    12 posts
    Member since:
    Jan 2010

    Posted 16 Feb 2010 Link to this post

    This is exactly what I need, THANK YOU, Shinu...you're so helpful!
  9. Amanda
    Amanda avatar
    65 posts
    Member since:
    Sep 2010

    Posted 07 Jan 2011 Link to this post

    Thank you so much for his code!  Worked great!
  10. kamal
    kamal avatar
    4 posts
    Member since:
    Dec 2010

    Posted 20 Aug 2011 Link to this post

    how to still open radwindow while redirecting to another page.
  11. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 22 Aug 2011 Link to this post

    Hello Kamal,

    The RadWindow is a control that "lives" in the page, so if you redirect to another one the old page is disposed and you cannot have a RadWindow open during this time, as its object is, naturally, also disposed. As for the new page - the earliest possible time when you can show a RadWindow is the Sys.Application.Load event, as this is when AJAX-enabled controls are loaded.


    Kind regards,
    Marin
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017