+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Ajax issue adding custom control to admin page

Ajax issue adding custom control to admin page

8 posts, 0 answered
  1. Alessio S.
    Alessio S. avatar
    37 posts
    Registered:
    31 May 2010
    31 Jan 2011
    Link to this post
    Hi,
    I'm adding a simple custom UserControl to the News editor in the admin page. I have already edited the template with other things but this is an Ajax control for some data which needs to go into a custom database table.
    There is a RadListBox which is populated in Page_Load plus a textbox with a button where the user can enter new values to be appended to the listbox. For the most part it works but the first time the button is clicked it causes the whole page to reload (and adds the new item correctly). From the second click on it updates only the listbox with ajax as expected.
    I tried removing the RadAjaxPanel but in that case the page gets realoded on each click of the button ignoring the RadAjaxManagerProxy settings.

    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Button1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadListBox1" />
                    <telerik:AjaxUpdatedControl ControlID="TextBox1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadAjaxPanel ID="Panel1" runat="server">
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <telerik:TextBoxEx ID="TextBox1" runat="server" MaxLength="250" />
        <asp:Button ID="Button1" runat="server" Text="Aggiungi" Width="70px" OnClick="Button1_Click" />
        <br />
        <telerik:RadListBox runat="server" ID="RadListBox1" CheckBoxes="True" Width="365px"
            Height="150px" SelectionMode="Multiple" CssClass="agevolazioni_listbox_fix">
        </telerik:RadListBox>
    </telerik:RadAjaxPanel>

    Code behind:
    protected void Button1_Click(object sender, EventArgs e)
        {
            string text = TextBox1.Text.Trim();
            if (text != string.Empty)
            {
                if (!RadListBox1.Items.Any(x => x.Text == text))
                {
                    int i = 0;
                    while (i < RadListBox1.Items.Count && StringLogicalComparer.Instance.Compare(RadListBox1.Items[i].Value, text) < 0)
                        i++;
                    RadListBox1.Items.Insert(i, new RadListBoxItem(text, text));
                    RadListBox1.Height = GetBoxHeight(RadListBox1.Items.Count);
                }
            }
            TextBox1.Text = string.Empty;
        }
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Feb 2011
    Link to this post
    Hello Alessio S.,

    Thank you for using our services.

    Can you please make sure that you have added a RadAjaxManager in the ~/Sitefinity/Admin/Admin.master master page file? The RadAjaxManager should be added right after the ScriptManager control.

    Kind regards,
    Radoslav Georgiev
    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
  3. Alessio S.
    Alessio S. avatar
    37 posts
    Registered:
    31 May 2010
    03 Feb 2011
    Link to this post
    The RadAjaxManager is there but it's empty (I haven't added Ajax managers/panels anywhere else in the admin pages):

    ...
    <asp:ScriptManager ID="TheScriptManager" runat="server" EnablePartialRendering="true"
            AsyncPostBackTimeout="600" EnableScriptGlobalization="true">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Personalization" Name="Telerik.Personalization.personalization.js" />
                <asp:ScriptReference Path="~/Scripts/jquery-1.4.2.min.js" />
            </Scripts>
        </asp:ScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <a href="#main" id="skip">Skip to the main content</a>
    ...
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    07 Feb 2011
    Link to this post
    Hello Alessio S.,

    It looks like AjaxSettings are not properly applied to the control on initial load. Can you please try setting them in Init event? You should get a reference of the ajax manager RadAjaxManager.GetCurrent(this.Page) and then if the manager is not null apply the settings.

    Regards,
    Radoslav Georgiev
    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
  5. Alessio S.
    Alessio S. avatar
    37 posts
    Registered:
    31 May 2010
    07 Feb 2011
    Link to this post
    I've tried adding this code to the UserControl's codefile:
    protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
     
            var manager = RadAjaxManager.GetCurrent(this.Page);
            /*if (manager != null)
            {
                manager.AjaxSettings.Add(
                    new AjaxSetting
                    {
                        AjaxControlID = Button1.ID,
                        UpdatedControls =
                        {
                            new AjaxUpdatedControl{ ControlID = Panel1.ID },
                            new AjaxUpdatedControl{ ControlID = RadListBox1.ID },
                            new AjaxUpdatedControl{ ControlID = TextBox1.ID },
                        }
                    });
            }*/
        }

    The manager is never null but its AjaxSettings member is empty (Count = 0). If I uncomment the commented part, AjaxSettings still comes back empty after every postback, and even adding the settings this way the button keeps behaving the same way, i.e. the first time it is pressed the page is fully reloaded.
    Note that I have several instances of this UserControl on the page. When I hit the breakpoint during a page load/postback I see the AjaxSetting objects inserted by the previously processed instances of the control, but only during the same page loading. After each postback the AjaxSettings starts out empty.
    Also my UserControls are inside the <sf:ContentMetaFields><ItemTemplate> block on the page template, maybe this has to with the problem.
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    27 Feb 2011
    Link to this post
    Hello Alessio S.,

    I have created a small sample project to illustrate how you can achieve Ajax functionality in the back-end. I have edited the ~/Sitefinity/Admin/ControlTemplates/News/NewsItemsList.ascx file. The administrative username and password are both admin.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. Stefano
    Stefano avatar
    29 posts
    Registered:
    14 Jun 2011
    13 Jul 2011
    Link to this post
    How can I integrate the project (zip file)  into sitefinity?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Jul 2011
    Link to this post
    Hi Stefano,

    Download the project and check ~/Sitefinity/Admin/ControlTemplates/News/NewsItemsList.ascx where Rado added sample code. You need to map the external template NewsItemsList.ascx as explained in this KB

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
8 posts, 0 answered