We help IT Professionals succeed at work.

Hoist the colors! We’ve added location flags to usernames sitewide, so it's easier to connect with the global community on EE. View My Profile


Replace ButtonClickEvent with RadWindow Close (ASP.NET, C#, Telerik RadControls)

XGIS asked
Last Modified: 2012-05-09
How do I change the ButtonClickEvent (C#) to the Telerik RadCloseWindow Client Side Event.  

The code "samples" from telerik show the NET and Javascript related to the Telerik RadWindow.  This action needs to then Fire off the C# tasks that the "Back to Lesson Selector" button does. THIS CODE IS NOT CURRENTLY IN MY SOLUTION. The problem is more javascript calling c# which is not my forte.

The Button Click event starts a number of C# tasks which include updating an MSSQL 2008  database as well as running some java to dynamically update the display of the the RadGrid database video 'hits'.  This IS the ACTUAL C# Code that needs to be controlled by the client side radwindow close.

My plan is to run it direct from the VideoSelector Page (embedded user control XGISVideoLessonVideo.jpg).  

The reason for this is to help resolve seperate display animation and resize issues/conflicts which play havoc with the radwindow display and the "Back to Lesson Selector" button .  ie the "Back to Lesson Selector" button is clicked but the RadWindow Repoens.  The Telerik animation is beneficial as it helps resolve image and video size differences, eliminating the need for setting fixed widths (for variable objects) which cause scrollbars to uneccesarily display.  The idea is that if I remove the dependency on the back button to the radwindow close event it will also resolve display issues I am having in IE8 vs correct display in chrome. ie less things to go wrong.

The endgame is to replace the 2nd ASPX page and run it all from the one page.

function controlWindowButtons()
                var selitem = null;
                var e = document.forms[0].elements["RadioButtonList1"];
                for (var i=0; i < e.length; i++)
                 if (e[i].checked)
                     selitem = e[i].value;
                eval("oWnd." + selitem);

Open in new window

onclick="controlWindowButtons()" Value="close()" Text="Close"

Open in new window

protected void Button1_Click(object sender, EventArgs e)
        string sql = "";
        var com = new SqlCommand();
        sql +=
            "INSERT INTO Xtrain.XTV7_3_Video_View (XTV7_VVR_Time_Start, XTV7_VVR_Time_Close, XTV7_UserName, XTV7_Videos_ID) Values (@XTV7_VVR_Time_Start, @XTV7_VVR_Time_Close, @XTV7_UserName, @XTV7_Videos_ID)";
        com.Parameters.Add("@XTV7_VVR_Time_Start", SqlDbType.DateTime).Value = DateTime.Parse(lblVidReg.Text);
        com.Parameters.Add("@XTV7_VVR_Time_Close", SqlDbType.DateTime).Value = DateTime.Parse(DateTime.Now.ToString());
        com.Parameters.Add("@XTV7_UserName", SqlDbType.NVarChar).Value = HttpContext.Current.User.Identity.Name.ToString();
        com.Parameters.Add("@XTV7_Videos_ID", SqlDbType.Int).Value = Int32.Parse(Geek.XTV7_Videos_ID.ToString());

            data.ExecuteNonQuery(sql, com);
        catch (Exception ex)
            string script = "<script language=\"JavaScript\">alert('Error :  " + ex.Message + "');</script>";
            Page.RegisterStartupScript("error", script);
        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);

        string scriptreturn = "<script type='text/javascript'>closeRadWindow('VideoViewer.aspx');</script>";
        ClientScript.RegisterStartupScript(GetType(), "Redirect", scriptreturn, false);

Open in new window

Current Javascript Close andRebind

         function CloseAndRebind(args) {

Open in new window

Watch Question

I use the RadControls all the time and really like them, however i have noticed that closing a RadWindow doesn't always work the way their examples say. In your CloseAndRebind method, try something like this:

var oBrowserWnd = GetRadWindow().BrowserWindow;
// Do your work here

For some reason adding the variable into that call was all i needed to get my RadWindows to close correctly. Hopefully i read what you were looking for correctly?


Hello TheMozz,

What i am after is a way to use the insert Statement 'as shown in the second code snippet' and hook it on the default RadWindow close button and get rid of the asp button.

Sorry about the misunderstanding!

So your looking to use the Back To Lesson Selector button to insert data into the database to track when the user viewed a video, then close the video window correct?
This one is on us!
(Get your first solution completely free - no credit card required)

Very nice! That's the first time i've seen the RadAjaxManager used like that, going to have to bookmark this page!!! Thank you for the reply and example :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.