Update Label text within RadWindow from code behind

5 posts, 1 answers
  1. Ben
    Ben avatar
    10 posts
    Member since:
    Dec 2011

    Posted 28 May 2012 Link to this post

    I have a RadWindow with a content template containing 3 labels. The window is displayed on Button click, but the labels do not update in the RadWindow, instead they keep thier default value. Any help would be great!

    Code is a as follows: -

    ASPX Page

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
        EnableShadow="True" KeepInScreenBounds="True" Behaviors="Close, Reload"
        Modal="True" ReloadOnShow="True" VisibleStatusbar="False">
    <Windows>
                <telerik:RadWindow ID="winRegisterSum" runat="server">
                <ContentTemplate>
                <br />
                <asp:Label ID="Label2" runat="server" Text="Submit register with the following:"></asp:Label>
                <br /><br />
                <asp:Label ID="lblPresents" runat="server" Text="Presents"></asp:Label>
                <br />
                <asp:Label ID="lblAbsents" runat="server" Text="Presents"></asp:Label>
                <br />
                <asp:Label ID="lblLates" runat="server" Text="Presents"></asp:Label>
                <br /><br />
                <asp:Button ID="btnConfirm" runat="server" Text="Confirm" CssClass="defaultButton" OnClick="btnConfirm_Click"/>
                </ContentTemplate>
                </telerik:RadWindow>
                    </Windows>
    </telerik:RadWindowManager>


    Code Behind

    Label lblPresents = winRegisterSum.ContentContainer.FindControl("lblPresents") as Label;
    Label lblAbsents = winRegisterSum.ContentContainer.FindControl("lblAbsents") as Label;
    Label lblLates = winRegisterSum.ContentContainer.FindControl("lblLates") as Label;
     
    lblPresents.Text = "New Label";
    lblAbsents.Text = "New Label";
    lblLates.Text = "New Label"
     
    string script = "function f(){$find(\"" + winRegisterSum.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
     
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
  2. Answer
    jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 29 May 2012 Link to this post

    Ben:

    I'd suggest that you reference the How to Use RadWindow with AJAX documentation page for insights on your requirement.

    You can wrap the ContentTemplate with an <asp:UpdatePanel> that will refresh the label values when the "Confirm" button is clicked, as follows:

    Default.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <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" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //script goes here
        </script>
        <div>
            <telerik:RadWindow runat="server" ID="winRegisterSum" VisibleOnPageLoad="true">
                <ContentTemplate>
                    <asp:UpdatePanel ID="Updatepanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <br />
                            <asp:Label ID="Label2" runat="server" Text="Submit register with the following:">
                            </asp:Label>
                            <br />
                            <br />
                            <asp:Label ID="lblPresents" runat="server" Text="Presents"></asp:Label>
                            <br />
                            <asp:Label ID="lblAbsents" runat="server" Text="Presents"></asp:Label>
                            <br />
                            <asp:Label ID="lblLates" runat="server" Text="Presents"></asp:Label>
                            <br />
                            <br />
                            <asp:Button ID="btnConfirm" runat="server" Text="Confirm" CssClass="defaultButton"
                                OnClick="btnConfirm_Click" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ContentTemplate>
            </telerik:RadWindow>
        </div>
        </form>
    </body>
    </html>

    Default.aspx.cs:
    using System;
    using System.Web;
    using System.Web.UI;
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
    {
     
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            lblPresents.Text = "New Label";
            lblAbsents.Text = "New Label";
            lblLates.Text = "New Label";
        }
     
    }

    See this in action at http://screencast.com/t/qfmiIvYd

    Hope this helps!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ben
    Ben avatar
    10 posts
    Member since:
    Dec 2011

    Posted 30 May 2012 Link to this post

    Works great, thanks!
  5. Pat
    Pat avatar
    3 posts
    Member since:
    May 2013

    Posted 10 May 2013 Link to this post

    hi,I have the same question , but, i want the label's text changed when  a button clicked,the button is out of radwindow.can u give me some suggestion
  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 15 May 2013 Link to this post

    Hi Pat,

    I have answered your other thread on the same matter that also has some more code in it and I suggest we continue the discussion of your issue there if needed.


    All the best,
    Marin Bratanov
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017