Dynamically Setting the Title of a RadWindow

4 posts, 0 answers
  1. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 11 Apr 2013 Link to this post

    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



  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3600 posts

    Posted 15 Apr 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 15 Apr 2013 Link to this post

    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
  5. Raj
    Raj avatar
    1 posts
    Member since:
    Jun 2014

    Posted 09 Jun 2014 in reply to Robert Link to this post

    Can you please post a snippet on how you got it working on the server side with the custom lable control?

    thanks,
    Raj
Back to Top