[CLOSED] UserControls and Events

  1. #1

    [CLOSED] UserControls and Events

    Hi,

    I will try to explain.

    I have a user control with some ext controls in it. One of these control (a combo) fires a AjaxEvent, after that event in code behind a 'regular' event is throw by user control and consumed by owner page that SHOULD update some ext textfield.

    Well everything works ok, except that last textfields are left untouched. I suppose the problem is related to AjaxEvent and javascript not injected to page.

    I tried to change the signature of UserControl Event as
    public event ComponentAjaxEvent.AjaxEventHandler but with no results.

    here a (simplified) snippet.

    Page
    <ext:Panel  runat="server"  Border="false" >
        <Body>
            <uc3:UserControl ID="_source" runat="server"  />                                           
        </Body>
    </ext:Panel>                       
    <ext:Panel runat="server">
            <ext:TextField runat="server" ID="_destination"  />
    </ext:Panel>
    
    ----CODE BEHIND
    protected void Page_Load( object sender, EventArgs e )
    {
        _source.Selected += new ComponentAjaxEvent.AjaxEventHandler(Selected);    
    }
    
    void Selected(object sender, AjaxEventArgs e)
    {
        _destination.Text = e.ExtraParams["Key"];
    }
    UserControl
    <ext:ComboBox ID="_Key"  >
        <AjaxEvents>
            <Select OnEvent="KeySelected" ViewStateMode="Include"  />
        </AjaxEvents>
    </ext:ComboBox>
    
    ----CODE BEHIND
    public event ComponentAjaxEvent.AjaxEventHandler Selected;
    
    protected void KeySelected(object sender, AjaxEventArgs e)
    {
        OnSelected( e );
    }
    
    private void OnSelected(AjaxEventArgs e)
    {
        if (Selected != null)
        {
            e.ExtraParams.Add(new Parameter("Key", _Key.SelectedItem.Text));        
            Selected(this,  e);
        }
    }
    at the end of trip _destination should have _source.SelectedItem: if I debug it actually assign this value, but nothing happens on UI.

    Thank you

    Stefano
  2. #2

    RE: [CLOSED] UserControls and Events

    Hi,

    Well, ExtraParams is not designed to add params manually during AjaxEvent. It is better to define all extra parameters beforehand
    But it seems to work correctly for me (0.8.2)

    Here is my test case
    Page
    <%@ Page Language="C#" %>
    <%@ Register Src="~/Panel/Child.ascx" TagName="UserControl" TagPrefix="uc3" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
        
        <script runat="server">
            protected void Page_Load( object sender, EventArgs e )
            {
                _source.Selected += new ComponentAjaxEvent.AjaxEventHandler(Selected);    
            }
    
            void Selected(object sender, AjaxEventArgs e)
            {
                _destination.Text = e.ExtraParams["Key"];
            }
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager runat="server"></ext:ScriptManager>
            
            <ext:Panel  runat="server"  Border="false" >
                <Body>
                    <uc3:UserControl ID="_source" runat="server"  />                                           
                </Body>
            </ext:Panel>                       
            <ext:Panel runat="server">
                <Body>
                    <ext:TextField runat="server" ID="_destination"  />
                </Body>                
            </ext:Panel>
    
        </form>
    </body>
    </html>
    UserControl
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        public event ComponentAjaxEvent.AjaxEventHandler Selected;
    
        protected void KeySelected(object sender, AjaxEventArgs e)
        {
            OnSelected( e );
        }
    
        private void OnSelected(AjaxEventArgs e)
        {
            if (Selected != null)
            {
                e.ExtraParams.Add(new Coolite.Ext.Web.Parameter("Key", _Key.SelectedItem.Text));        
                Selected(this,  e);
            }
        }
    </script>
    
    <ext:ComboBox ID="_Key" runat="server"  >
        <Items>
            <ext:ListItem Text="Item" />
        </Items>
        <AjaxEvents>
            <Select OnEvent="KeySelected" ViewStateMode="Include"  />
        </AjaxEvents>
    </ext:ComboBox>
    Please provide your test sample which demonstrates the issue
  3. #3

    RE: [CLOSED] UserControls and Events


    Hi,

    I found the problem: it's a placeholder containinga store created in code behind. If I remove it and replace it with a markup created the problem is gone.

    something like this
    <ext:Panel  runat="server"  Border="false" >
        <Body>
            <uc3:UserControl ID="_source" runat="server"  />                                           
        </Body>
    </ext:Panel>                       
    <ext:Panel runat="server">
            <ext:TextField runat="server" ID="_destination"  />
    </ext:Panel><asp:PlaceHolder />
    <ext:Panel  runat="server"  Border="false" >
        <Body>
            <uc3:UserControl ID="_source" runat="server"  />                                           
        </Body>
    </ext:Panel>
    I don't understand why, but: it is! Can you help me understand why? For now you can mark the thread as closed.

    Stefano
  4. #4

    RE: [CLOSED] UserControls and Events

    Hi,

    Can you help me understand why?
    I need a test sample which demonstrates that case

Similar Threads

  1. [CLOSED] Loader with UserControls
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 13
    Last Post: Jun 29, 2012, 12:08 PM
  2. Replies: 15
    Last Post: Feb 03, 2011, 1:27 PM
  3. [CLOSED] UserControls within FormPanel
    By drgw74 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 30, 2010, 1:45 PM
  4. [CLOSED] AjaxMethods in UserControls
    By Justin_Wignall in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Nov 19, 2009, 8:39 AM
  5. Replies: 3
    Last Post: Mar 19, 2009, 3:26 PM

Posting Permissions