Show lightbox code behind

3 posts, 0 answers
  1. Troy Clemons
    Troy Clemons avatar
    69 posts
    Member since:
    Apr 2010

    Posted 09 Jan 2014 Link to this post

    is there a way to show the lightbox from code behind.

    e.g. RadLightBox1.Show()

  2. Kostadin
    Kostadin avatar
    1733 posts

    Posted 14 Jan 2014 Link to this post

    Hello Troy,

    Thank you for contacting us.

    Since RadLigthBox is rendered completely on the client there isn't an option to open in from code behind.

    I hope this information proves helpful.

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. Ken
    Ken avatar
    4 posts
    Member since:
    Nov 2006

    Posted 07 Nov 2014 Link to this post

    It has been many months since this question from Troy, but we had the same need and came up with a working solution.  The solution to the problem entails a combination of AJAX and JavaScript.  All necessary code is in the default.aspx and default.aspx.vb files.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    var lightBox;
                    var lightBoxVisible = false;
                    function OpenLightBox() {
                        lightBoxVisible = true;
                        lightBox = $find('<%=RadLightBox1.ClientID%>');
                    $telerik.$(document).ready(function () {
                        if (lightBoxVisible === true) {
                            lightBox = $find('<%=RadLightBox1.ClientID%>');
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
                <telerik:AjaxSetting AjaxControlID="RadButton1">
                        <telerik:AjaxUpdatedControl ControlID="RadLightBox1" />
        <telerik:RadLightBox ID="RadLightBox1" runat="server" Modal="true" ShowMaximizeButton="false" ShowNextButton="false" ShowPrevButton="false" >
                <AnimationSettings HideAnimation="Resize" ShowAnimation="Resize" />
                        <telerik:RadTextBox ID="RadTextBox1" runat="server" TextMode="MultiLine" Width="300px" Height="80px" ReadOnly="true" />
            <telerik:RadButton ID="RadButton1" runat="server" Text="Cause Callback" />

    Imports Telerik.Web.UI
    Partial Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
            ' needed to load scripts each callback/postback
            AddHandler Me.PreRender, AddressOf RegisterScript
        End Sub
        Private _functions As New List(Of String)
        ' add functions to list to be sent back to the page
        Public Sub RegisterCustomScript(script As String)
            ' ensure script ends with ;
            If Not script.EndsWith(";") Then
                script &= ";"
            End If
            ' don't register duplicate scripts
            If Not _functions.Contains(script) Then _functions.Add(script)
        End Sub
        ' load Javascript functions into callback/postback code
        Protected Sub RegisterScript(sender As Object, e As EventArgs)
            If _functions.Count > 0 Then
                ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "myScripts", "function f(){" & String.Format("{0}", String.Join(" ", _functions)) & "; Sys.Application.remove_load(f);} Sys.Application.add_load(f);", True)
            End If
        End Sub
        Protected Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
            ' find textbox in the RadLightBox
            Dim RadTextboxControl As RadTextBox = RadLightBox1.FindControl("RadTextBox1")
            ' add misc. data to the textbox to show we were here
            RadTextboxControl.Text &= Now().ToString & vbCrLf
            ' cause the RadLightBox to show after callback
        End Sub
    End Class
Back to Top