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

RadWindow close on server side

9 Answers 659 Views
Window
This is a migrated thread and some comments may be shown as answers.
drpcken
Top achievements
Rank 1
drpcken asked on 29 Apr 2009, 04:53 AM
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.

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2009, 09:44 AM
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.
0
drpcken
Top achievements
Rank 1
answered on 29 Apr 2009, 02:48 PM
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?
0
Shinu
Top achievements
Rank 2
answered on 30 Apr 2009, 06:03 AM
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.
0
Michael
Top achievements
Rank 2
answered on 14 Jan 2010, 02:30 PM
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.
0
Fiko
Telerik team
answered on 14 Jan 2010, 03:13 PM
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.
0
Pei Chen
Top achievements
Rank 1
answered on 16 Feb 2010, 04:19 PM
This is exactly what I need, THANK YOU, Shinu...you're so helpful!
0
Amanda
Top achievements
Rank 1
answered on 07 Jan 2011, 05:25 PM
Thank you so much for his code!  Worked great!
0
kamal
Top achievements
Rank 1
answered on 20 Aug 2011, 08:33 AM
how to still open radwindow while redirecting to another page.
0
Marin Bratanov
Telerik team
answered on 22 Aug 2011, 03:34 PM
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 >>

Tags
Window
Asked by
drpcken
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
drpcken
Top achievements
Rank 1
Michael
Top achievements
Rank 2
Fiko
Telerik team
Pei Chen
Top achievements
Rank 1
Amanda
Top achievements
Rank 1
kamal
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or