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

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

2 Answers 201 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Dave Crack
Top achievements
Rank 1
Dave Crack asked on 18 Mar 2010, 04:37 PM
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 Answers, 1 is accepted

Sort by
0
Dave Crack
Top achievements
Rank 1
answered on 22 Mar 2010, 01:09 PM
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?


0
Pero
Telerik team
answered on 23 Mar 2010, 09:33 AM
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.
Tags
Dock
Asked by
Dave Crack
Top achievements
Rank 1
Answers by
Dave Crack
Top achievements
Rank 1
Pero
Telerik team
Share this question
or