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

Dynamically Setting the Title of a RadWindow

3 Answers 1526 Views
Window
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 11 Apr 2013, 05:51 PM
In my ASP.NET 4.0 project, I have many RadWindow-powered dialog boxes that are defined like this partial code example:

<telerik:RadWindow ID="rwChangePassword" runat="server" Behaviors="Close,Move" EnableShadow="true" VisibleStatusbar="false" VisibleTitlebar="true" AutoSize="true" Modal="true">
  <ContentTemplate>
    <div class="dialogMain smallText" style="width:330px">
      <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
          <div style="margin:10px 0 0 5px">
            <div style="width:95%">
              Please enter the user's new password, enter it a second time to confirm, and then press OK:
            </div>
            .
            .
            .

To turn them on/off I use server-side code like this:

public bool ModalDialogIsActive
{
  get
  {
    return Convert.ToBoolean(ViewState["ModalDialogIsActive"]);  // Note: Returns 'false' if the value is 'null'
  }
 
  set
  {
    if (value)
      Website.Common.ShowDialog(rwChangePassword);
    else
      Website.Common.HideDialog(rwChangePassword);
 
    ViewState["ModalDialogIsActive"] = value;
  }
}

That all works fine.  But now I'm trying to introduce a title to such a dialog, which I will dynamically generate depending on various factors.  For example, for the Change Password dialog box above, I might have a title like "Changing Password for John Smith".

I tried doing this by simply setting the Title property of the RadWindow before activating the dialog box.  Here's an example:

rwChangePassword.Title = "Changing Password for " + userName;
ModalDialogIsActive = true;

This didn't work though.  No matter what I tried, the title always remained blank.

So how does one dynamically set the Title of a RadWindow?

Robert



3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 15 Apr 2013, 12:00 PM
Hi Robert,

If you have attempted to change the server property of the RadWindow during a partial postback which does not update the control itself it should be expected that the new value will not be carried to the client where you can see it in the browser.

Generally, RadWindow's title can be changed either through the server Title property, or through its client-side API - the set_title(string) method.

What I can suggest is storing the title in a hidden field inside the content template (and inside the update panel to make sure it comes down to the browser) and then a simple jQuery selector in the OnClientShow event of the dialog can get the title from the hidden field. For example:

<script type="text/javascript">
    function setPopupTitle(sender)
    {
        var hfValue = $telerik.$('input[id$="dialogTitle"]', sender.get_contentElement()).val();
        if (hfValue)
        {
            sender.set_title(hfValue);
        }
        else
        {
            sender.set_title("some generic title");
        }
    }
</script>
<telerik:RadWindow ID="rwChangePassword" runat="server" Behaviors="Close,Move" EnableShadow="true"
    VisibleStatusbar="false" VisibleTitlebar="true" AutoSize="true" Modal="true"
    OnClientShow="setPopupTitle">
    <ContentTemplate>
        <div class="dialogMain smallText" style="width: 330px">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:HiddenField runat="server" ID="dialogTitle" />
                    <div style="margin: 10px 0 0 5px">
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
    </ContentTemplate>
</telerik:RadWindow>



Greetings,
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.
0
Robert
Top achievements
Rank 1
answered on 15 Apr 2013, 02:58 PM
Marin,

Thank you for your response.  I do understand your approach.

However, this past weekend I opted for another approach which implements a custom Label control which I can set server-side.  It's a much cleaner approach.  I've enclosed a screenshot example.

Robert
0
Raj
Top achievements
Rank 1
answered on 09 Jun 2014, 07:40 PM
Can you please post a snippet on how you got it working on the server side with the custom lable control?

thanks,
Raj
Tags
Window
Asked by
Robert
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Robert
Top achievements
Rank 1
Raj
Top achievements
Rank 1
Share this question
or