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

Update Label text within RadWindow from code behind

4 Answers 530 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 28 May 2012, 12:27 PM

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);

4 Answers, 1 is accepted

Sort by
0
Accepted
Richard
Top achievements
Rank 1
answered on 29 May 2012, 07:49 PM
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!
0
Ben
Top achievements
Rank 1
answered on 30 May 2012, 01:31 PM
Works great, thanks!
0
Pat
Top achievements
Rank 1
answered on 11 May 2013, 02:15 AM
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
0
Marin Bratanov
Telerik team
answered on 15 May 2013, 10:00 AM
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.
Tags
Window
Asked by
Ben
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Pat
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or