Creating web server control

2 posts, 0 answers
  1. Tiago
    Tiago avatar
    1 posts
    Member since:
    May 2009

    Posted 05 Feb 2010 Link to this post

    Hello,


    When I create a Web Server Control with RadAjaxManager, RadAjaxLoadingPanel and RadGrid inside, all working properly, but if for example I change page on RadGrid, Ajax works fine, but on second time I change the page, Ajax stops working, and the third time I change page, Ajax works fine again...


    I don't understand why this append


    My code here...


    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Linq; 
    using System.Text; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.Web.UI; 
    using System.IO; 
    using System.Reflection; 
    using darwin.sadj.shared.core; 
    [assembly: WebResource("darwin.sadj.shared.ui.etiqueta.Imagens.delete.gif""image/gif")] 
    namespace darwin.sadj.shared.ui.etiqueta 
        [ToolboxData("<{0}:ListEtiqueta runat=server></{0}:ListEtiqueta>")] 
        public class ListEtiqueta : WebControl 
        { 
            private RadGrid gridEtiquetas { getset; } 
            private RadAjaxManager RadAjaxManager1 { getset; } 
            private RadAjaxLoadingPanel RadAjaxLoadingPanel1 { getset; } 
            protected override void OnInit(EventArgs e) 
            { 
                this.Controls.Clear(); 
                RadAjaxLoadingPanel1 = new RadAjaxLoadingPanel(); 
                RadAjaxLoadingPanel1.ID = this.ID + "_RadAjaxLoadingPanel"
                this.Controls.Add(RadAjaxLoadingPanel1); 
                RadAjaxManager1 = new RadAjaxManager(); 
                RadAjaxManager1.ID = this.ID + "_RadAjaxManager"
                this.Controls.Add(RadAjaxManager1); 
                gridEtiquetas = new RadGrid(); 
                gridEtiquetas.ID = this.ID + "_gridEtiquetas"
                gridEtiquetas.NeedDataSource += new GridNeedDataSourceEventHandler(gridEtiquetas_NeedDataSource); 
                gridEtiquetas.ItemCommand += new GridCommandEventHandler(gridEtiquetas_ItemCommand); 
                this.Controls.Add(gridEtiquetas); 
                base.OnInit(e); 
            } 
            protected override void RenderContents(HtmlTextWriter output) 
            { 
                if (this.Visible == true
                { 
                    this.RadAjaxLoadingPanel1.RenderControl(output); 
                    this.RadAjaxManager1.RenderControl(output); 
                    this.gridEtiquetas.RenderControl(output); 
                } 
            } 
            protected override void OnLoad(EventArgs e) 
            { 
                if (!this.Page.IsPostBack) 
                { 
                    GridBoundColumn colunaID = new GridBoundColumn(); 
                    gridEtiquetas.Columns.Add(colunaID); 
                    colunaID.DataField = "Id"
                    colunaID.UniqueName = "Id"
                    colunaID.HeaderText = "Id"
                    GridBoundColumn colunaDescricao = new GridBoundColumn(); 
                    gridEtiquetas.Columns.Add(colunaDescricao); 
                    colunaDescricao.DataField = "Descricao"
                    colunaDescricao.UniqueName = "Descricao"
                    colunaDescricao.HeaderText = "Descrição"
                    GridButtonColumn colunaDelete = new GridButtonColumn(); 
                    gridEtiquetas.Columns.Add(colunaDelete); 
                    colunaDelete.ButtonType = GridButtonColumnType.ImageButton; 
                    colunaDelete.CommandName = "Delete"
                    colunaDelete.ConfirmDialogType = GridConfirmDialogType.RadWindow; 
                    colunaDelete.ConfirmText = "Deseja apagar este registo?"
                    colunaDelete.ConfirmTitle = "Confirmação"
                    colunaDelete.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "darwin.sadj.shared.ui.etiqueta.Imagens.delete.gif"); 
                    colunaDelete.Text = "Apagar"
                    colunaDelete.UniqueName = "colunaDelete"
                    colunaDelete.ItemStyle.Width = Unit.Pixel(22); 
                } 
                gridEtiquetas.AutoGenerateColumns = false
                gridEtiquetas.GridLines = GridLines.None; 
                gridEtiquetas.MasterTableView.AllowCustomPaging = true
                gridEtiquetas.MasterTableView.AllowPaging = true
                gridEtiquetas.MasterTableView.PagerStyle.Mode = GridPagerMode.NextPrev; 
                gridEtiquetas.MasterTableView.DataKeyNames = new string[] { "Id" }; 
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(gridEtiquetas, gridEtiquetas, RadAjaxLoadingPanel1); 
                 
                base.OnLoad(e); 
            } 
            protected void gridEtiquetas_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
            { 
                EtiquetaController controller = new EtiquetaController(); 
                int TotalRecords = 0; 
                ((RadGrid)source).DataSource = controller.getListEtiqueta(((RadGrid)source).MasterTableView.CurrentPageIndex, ((RadGrid)source).MasterTableView.PageSize, out TotalRecords); 
                ((RadGrid)source).MasterTableView.VirtualItemCount = TotalRecords; 
            } 
            protected void gridEtiquetas_ItemCommand(object source, GridCommandEventArgs e) 
            { 
                if (e.CommandName == "Delete"
                { 
                    EtiquetaController controller = new EtiquetaController(); 
                    controller.deleteEtiqueta(Convert.ToInt64(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"])); 
                } 
            } 
        } 

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 08 Feb 2010 Link to this post

    Hello Tiago,

    I am afraid that you cannot render RadAjaxManager as in your code. You  should simply call the base of RenderContents to have RadAjaxManager function properly.

    1.protected override void RenderContents(HtmlTextWriter output)
    2.{
    3.   base.RenderContents(output);
    4.}



    Greetings,
    Nikolay
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Back to Top