We help IT Professionals succeed at work.

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

XGIS
XGIS asked
on
7,229 Views
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)";
            //Geek.XTV7_VidReg;
        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());

        try
        {
            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) {
                GetRadWindow().BrowserWindow.refreshGrid(args);
                GetRadWindow().close();
            }

Open in new window

CurrentLessonDisplay-Videos-Imag.jpg
VideoSearchAndStart.jpg
Comment
Watch Question

Commented:
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
oBrowserWnd.close();

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?

Author

Commented:
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.

Commented:
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?
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Commented:
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 :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions