Telerik ASP.NET AJAX - Ajax Update Label with dynamically created Docks

3 posts, 0 answers
  1. Dave Crack
    Dave Crack avatar
    5 posts
    Member since:
    Mar 2010

    Posted 18 Mar 2010 Link to this post

    Hi,

    i try to Update a simple Label on Close Event of dynamic created RadDock.
    Works fine so far, Label gets the correct values but doesnt updates it.

           RadDock dock = new RadDock(); 
                    dock.DockMode = DockMode.Docked; 
                    dock.UniqueName = Guid.NewGuid().ToString(); 
                    dock.ID = string.Format("RadDock{0}", dock.UniqueName); 
                    dock.Title = slide.slideName; 
                    dock.Text = string.Format("Added at {0}", DateTime.Now); 
                    dock.Width = Unit.Pixel(300); 
                dock.AutoPostBack = true
                dock.CommandsAutoPostBack = true
                dock.Command += new DockCommandEventHandler(dock_Command); 
     
        ... 
     
        void dock_Command(object sender, DockCommandEventArgs e) 
        { 
        Status.Text = "Removed " + ((RadDock)sender).Title + " " + ((RadDock)sender).Text; 
        } 

    I tried to do this:
    RadAjaxManager1.AjaxSettings.AddAjaxSetting(dock, Status, null); 

    while creating the docks, but on runtime i get a NullReference Excepetion.






    On a Button registered with the RadAjaxManager it works to show the value
    assigned by dock_command.

     
            protected void Button1_Click(object sender, EventArgs e) 
            { 
                Status.Text = Status.Text; 
            } 











           RadDock dock = new RadDock(); 
                    dock.DockMode = DockMode.Docked; 
                    dock.UniqueName = Guid.NewGuid().ToString(); 
                    dock.ID = string.Format("RadDock{0}", dock.UniqueName); 
                    dock.Title = slide.slideName; 
                    dock.Text = string.Format("Added at {0}", DateTime.Now); 
                    dock.Width = Unit.Pixel(300); 
                dock.AutoPostBack = true
                dock.CommandsAutoPostBack = true
                dock.Command += new DockCommandEventHandler(dock_Command); 
     
        ... 
     
        void dock_Command(object sender, DockCommandEventArgs e) 
        { 
        Status.Text = "Removed " + ((RadDock)sender).Title + " " + ((RadDock)sender).Text; 
        } 






  2. Dave Crack
    Dave Crack avatar
    5 posts
    Member since:
    Mar 2010

    Posted 22 Mar 2010 Link to this post

    Any idea why I get always runtime error with null reference exception on
    the AddAjaxSettings?

            private RadDock CreateRadDockFromState(DockState state) 
            { 
                RadDock dock = new RadDock(); 
                dock.DockMode = DockMode.Docked; 
                dock.ID = string.Format("RadDock{0}", state.UniqueName); 
                dock.ApplyState(state); 
                dock.Commands.Add(new DockCloseCommand()); 
                dock.Commands.Add(new DockExpandCollapseCommand()); 
     
                RadTextBox box = new RadTextBox(); 
                box.AutoPostBack = true
                box.TextChanged += new EventHandler(box_TextChanged); 
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(box, this.Status); 
                dock.ContentContainer.Controls.Add(box); 
     
                return dock; 

    this.Status is a standard label.

    Is it even possible to add any AJAX to dynamic content?


  3. Pero
    Admin
    Pero avatar
    1156 posts
    Member since:
    Sep 2012

    Posted 23 Mar 2010 Link to this post

    Hello Dave,

    I think the problem might be caused by the fact that, when the dock is created for the first time you are not adding the commands explicitly, and at any other time (i.e. on every postback) the dock is created from state with commands added explicitly. My suggestion is to always add the commands explicitly, as shown in the following sample code:

    .aspx

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            </Scripts>
        </asp:ScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div>
            <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
                <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
                </telerik:RadDockZone>
            </telerik:RadDockLayout>
        </div>
        <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
        </form>
    </body>
    </html>


    .cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class DockCustomCommands : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            CreateDock(RadDockZone1);
        }
     
        private void CreateDock(RadDockZone zone)
        {
            RadDock dock = new RadDock();
            dock.ID = "RadDock1";
            dock.Width = Unit.Pixel(300);
            dock.Height = Unit.Pixel(300);
     
            dock.Commands.Add(new DockCloseCommand());
            dock.Commands.Add(new DockExpandCollapseCommand());
     
            dock.AutoPostBack = true;
     
            dock.CommandsAutoPostBack = true;
            dock.Command += new DockCommandEventHandler(dock_Command);
     
            AjaxUpdatedControl control = new AjaxUpdatedControl();
            control.ControlID = Label1.ID;
     
            AjaxSetting setting = new AjaxSetting(dock.ID);
            setting.EventName = "Command";
            setting.UpdatedControls.Add(control);
     
            RadAjaxManager1.AjaxSettings.Add(setting);
     
            RadDockZone1.Controls.Add(dock);
        }
     
        protected void dock_Command(object sender, DockCommandEventArgs e)
        {
            Label1.Text = e.Command.Name + " was clicked!";
        }
    }



    Kind regards,
    Pero
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Back to Top