Problem with Ajaxevents on dynamically created ComboBox

  1. #1

    Problem with Ajaxevents on dynamically created ComboBox

    Hello all,
    I have a desktop window, which controls dinamically created in code behind, based on the properties of an object being edited on the form.
    For some Comboboxes on that form i need to have an ajax-event every time the selection is changed.

    When I try this in markup with the code below, it works just fine:
    <ext:ComboBox ID="cbPatientList" runat="server" Enabled="false" FieldLabel="Patients"
                                    Width="200">
                                    <AjaxEvents>
                                        <Select OnEvent="cbPatientsListSelect">
                                        </Select>
                                    </AjaxEvents>
                                </ext:ComboBox>
    But when i use any of the events below in code behind, nothing happens when element is selected:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
    ...
     var field = ClientUtils.GetFieldByPropertyDescriptor(prop, out valueFieldName);
                    if (field != null && field is ComboBox)
                        {
    var comboBox = field as ComboBox;
                            comboBox.AjaxEvents.Select.Event += new ComponentAjaxEvent.AjaxEventHandler(Select_Event);
                            
                            comboBox.ItemSelected += new EventHandler(ComboItemSelected);
                            comboBox.ValueChanged += new EventHandler(ComboValueChanged);
                            comboBox.Listeners.Change.Handler = "Coolite.AjaxMethods.newCompany();";
                         }
     var anchor = new Anchor();
                        anchor.Items.Add(field);
                        FormLayout33.Anchors.Add(anchor);
    ...
    }
     void ComboValueChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    
        void ComboItemSelected(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    
        public void Select_Event(object sender, AjaxEventArgs e)
        {
            throw new NotImplementedException();
        }
    
        [AjaxMethod]
        public void newCompany()
        {
        }
    What am i doing wrong?
  2. #2
    Hi,

    Any dynamic ASP.NET control must be recreated on every request (also always provide ID for dynamic control).
    Please see
    http://forums.asp.net/t/1186195.aspx
    http://www.4guysfromrolla.com/articles/092904-1.aspx
  3. #3
    Thanks for looking into this Vlad.
    The problem here is that these events do not work even at the first time when the desktop is loaded, i.e. when there were no postbacks yet and hence no need to recreate the controls.

    Also, i have forgotten one important thing.
    When i bind to combobox.AjaxEvents.Select.Event and then change the selected item in control, the event at the client side is actually being raised, but with the following error:

    [HttpException (0x80004005): The control with ID 'ucpatientsList2_EditControl1_RegistrationIDStr' not found]
    Coolite.Ext.Web.ScriptManager.RaisePostBackEvent(S tring eventArgument) +1061
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +175
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

    So it's like the control does not exist, but i can see it on the form and in the DOM model.

    Also, I have a doubt that i need to recreate all the dynamic controls, as i have such windows already and they don't loose their controls when i have ajaxevents from other windows. The only thing i had to do is rebind to the control events every time i have an ajax event.
  4. #4
    Thanks for the links Vlad

Similar Threads

  1. Replies: 0
    Last Post: Apr 07, 2011, 8:48 PM
  2. Replies: 6
    Last Post: Nov 02, 2010, 3:25 PM
  3. [CLOSED] [1.0] Dynamically created control problem
    By galeb in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Aug 19, 2010, 7:16 AM
  4. [CLOSED] add handler to dynamically created combobox/textbox
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 11, 2010, 8:51 AM
  5. Replies: 3
    Last Post: Jun 05, 2008, 11:31 PM

Tags for this Thread

Posting Permissions