Can't access textbox controls in my docks

2 posts, 0 answers
  1. Chris
    Chris avatar
    58 posts
    Member since:
    Feb 2012

    Posted 15 May 2013 Link to this post

    Hi there,

    Very simple example of wht I'm trying to create here. It's so simple I can't figure out what am I doing wrong.
    This is based on this example from Telerik. Basically I just wanna edit some text in my dynamically created dock.

    Here's the code of the usercontrol I'm loading within my dock :
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="widgetTemplate.ascx.cs" Inherits="NRP.Monitors.usercontrols.widgetTemplate" %>
    <div class="widget">
        <table>
            <tr>
                <td rowspan="2" class="wicon">
                    <asp:Image ID="Wicon" runat="server" />
                </td>
                <td class="wtitle">
                    <asp:TextBox ID="TbTitle" runat="server" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="LbWtitle" runat="server" OnClick="LbWtitle_Click"></asp:LinkButton>
                </td>
            </tr>
            <tr>
                <td class="wsubtitle">
                    <asp:TextBox ID="TbSubtitle" runat="server" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="LbSubtitle" runat="server" OnClick="LbSubtitle_Click"></asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>

    And the code behind:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace NRP.Monitors.usercontrols
    {
        public partial class widgetTemplate : System.Web.UI.UserControl
        {
            public string Wtitle;
            public string WSubtitle;
            public string IconUrl;
     
            public widgetTemplate()
            {
            }
            public widgetTemplate(string wtitle, string wsubtitle, string iconUrl)
            {
                Wtitle = wtitle;
                WSubtitle = wsubtitle;
                IconUrl = "../" + iconUrl;
            }
     
            protected void Page_Load(object sender, EventArgs e)
            {
                LbWtitle.Text = Wtitle;
                LbSubtitle.Text = WSubtitle;
                Wicon.ImageUrl = IconUrl;
            }
     
            protected void LbWtitle_Click(object sender, EventArgs e)
            {
                if (TbTitle.Visible)
                {
                    LbWtitle.Text = TbTitle.Text;
                    Wtitle = TbTitle.Text;
                    TbTitle.Visible = false;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "enabledrag", "enableDockDrag(true);", true);
                }
                else
                {
                    TbTitle.Text = LbWtitle.Text;
                    LbWtitle.Text = "OK";
                    TbTitle.Visible = true;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "enabledrag", "enableDockDrag(false);", true);
                }
            }
     
            protected void LbSubtitle_Click(object sender, EventArgs e)
            {
                if (TbSubtitle.Visible)
                {
                    LbSubtitle.Text = TbSubtitle.Text;
                    WSubtitle = TbSubtitle.Text;
                    TbSubtitle.Visible = false;
                }
                else
                {
                    TbSubtitle.Text = LbSubtitle.Text;
                    LbSubtitle.Text = "OK";
                    TbSubtitle.Visible = true;
                }
            }
        }

    Everything works perfectly except that I can't change the content of the textboxes. Their value are set properly, but it looks like I can't access them to edit the text.
    As I said this is not rocket science but I can't figure out what's going on here.

    Anyone have some idea ?

    Thanks

  2. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 18 May 2013 Link to this post

    Hi Chris,

    Most probably the problem is caused by your implementation of the client-side function enableDockDrag which is required in order to disable the dragging and access the text box in the RadDock title bar, when enable its editing. In the following code sample you can check how to modify this function according to your setup:
    <script type="text/javascript">
        function enableDockDrag(enable) {
            var dock = $find("<%= Page.FindControl("RadDock1").ClientID%>");
                 if (enable) {
                     dock._initializeDrag();
                     var textbox = $get("<%=TbTitle.ClientID%>");
                      if (textbox) {
                          $addHandler(textbox, "mousedown", function (e) {
                              e.stopPropagation();
                          });
                      }
                      var textbox2 = $get("<%=TbSubtitle.ClientID%>");
                        if (textbox2) {
                            $addHandler(textbox2, "mousedown", function (e) {
                                e.stopPropagation();
                            });
                        }
                    }
                    else dock._disposeDrag();
                }
    </script>
    <div class="widget">
        <table>
            <tr>
                <td rowspan="2" class="wicon">
                    <asp:Image ID="Wicon" runat="server" />
                </td>
                <td class="wtitle">
                    <asp:TextBox ID="TbTitle" runat="server" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="LbWtitle" runat="server" OnClick="LbWtitle_Click"></asp:LinkButton>
                </td>
            </tr>
            <tr>
                <td class="wsubtitle">
                    <asp:TextBox ID="TbSubtitle" runat="server" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="LbSubtitle" runat="server" OnClick="LbSubtitle_Click"></asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
    Note that the RadDock is referenced through the page in which the user control is added.

    Regards,
    Slav
    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
Back to Top