Problem adding controls dynamically to a page. Refreshing lasts forever.

  1. #1

    Problem adding controls dynamically to a page. Refreshing lasts forever.

    Hi,

    I am new to this and trying to figure out how to add controls dynamically to a page. I wrote a test case but that does not seems to be working. I get a Refreshing... and Firefox Error console shows errors.

    using System;
    using System.Web;
    using Coolite.Ext.Web;
    
    public partial class _Default : System.Web.UI.Page
    {
        Coolite.Ext.Web.Panel p = null;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            Coolite.Ext.Web.ScriptManager sm = new Coolite.Ext.Web.ScriptManager();
            Controls.Add(sm);
            p = new Coolite.Ext.Web.Panel();       
            Coolite.Ext.Web.Button myButton = new Coolite.Ext.Web.Button();
            p.Controls.Add(myButton);
            Controls.Add(p);
            myButton.AjaxEvents.Click.Event += new ComponentAjaxEvent.AjaxEventHandler(Click_Event);
            sm.AddUpdatePanelToRefresh(p);
        }
    
        void Click_Event(object sender, AjaxEventArgs e)
        {
            Coolite.Ext.Web.Button myButton = (Coolite.Ext.Web.Button)sender;
            myButton.Text = "You have clicked me!";
            Coolite.Ext.Web.Label l = new Coolite.Ext.Web.Label("Add this label here!");
            p.Add(l);
            p.Reload();
        }
    }
    Any clue how to get this to work?
    All I need is the ability to add controls at runtime. This is for a custom control to render contents based on certain values.
  2. #2

    RE: Problem adding controls dynamically to a page. Refreshing lasts forever.




    You can not dynamically add controls on the serverside with v0.8. This functionality will be available in v1.0. You are probably getting the loading screen forever because you are calling pnl.reload().
  3. #3

    RE: Problem adding controls dynamically to a page. Refreshing lasts forever.

    Hi jacktripper1000,

    Yes, I can confirm the response of @jchau... your code will work in v1.0 but not v0.8.


    In v1.0 you'll just need to call .Render() instead of .Reload().


    Geoffrey McGill
    Founder

Similar Threads

  1. Dynamically adding Controls to WebUserControl
    By bright in forum 1.x Help
    Replies: 8
    Last Post: Apr 27, 2012, 6:34 PM
  2. Replies: 2
    Last Post: Dec 15, 2011, 11:58 AM
  3. Replies: 2
    Last Post: Feb 16, 2011, 9:10 AM
  4. Replies: 1
    Last Post: Aug 17, 2010, 10:07 PM
  5. [CLOSED] Dynamically adding controls to a tav
    By riccardosarti in forum 1.x Help
    Replies: 3
    Last Post: Sep 24, 2008, 9:49 AM

Posting Permissions