Listener problem in dynamics forms inherited from WebControl

  1. #1

    Listener problem in dynamics forms inherited from WebControl

    Hello,
    I'm trying Coolite v0.8.1 and I have a little problem with dynamics forms.
    I need to develop reusable forms (inherit from WebControl, in a DLL), and build this form in a dynamic way.
    Something like this:
    public partial class CustomerEditControl: System.Web.UI.WebControls.WebControl
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            
            // build the layout
            Panel pnl = new Panel();
            ...etc...
            
            this.Controls.Add(pnl);
        }
    etc..
    
        private void newButtonClicked() { ... }
    }
    all is working very fine (and fast), but the problem comes when I try to set the 'new' button handler.

    I've tried:
    btnNew.Listeners.Click.Handler = "#{CustomerEditControl}.newButtonClicked();";
    but it doesn't work. Nothing happens when I click the button.
    I also tried using the ClientID 'ctl' getting the same result (Java Console: "Coolite.AjaxMethods.ctl is undefined")

    Any ideas?

    Thanks in advance,

    Gustavo (from Argentina)

  2. #2

    RE: Listener problem in dynamics forms inherited from WebControl

    I'm not sure if you're trying to configure a client-side or server-side event handler, but the following sample demonstrates both.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="Button=Coolite.Ext.Web.Button" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    
    <script runat="server">
        protected override void OnInit(EventArgs e)
        {
            Button button = new Button();
            button.Text = "Server Click";
            button.AjaxEvents.Click.Event += Button1_Click;
    
            Button button2 = new Button();
            button2.Text = "Client Click";
            button2.Listeners.Click.Handler = "#{Label1}.setText('Client Time: ' + new Date());";
    
            this.form1.Controls.Add(button);
            this.form1.Controls.Add(button2);
        
            base.OnInit(e);
        }
            
        protected void Button1_Click (object sender, AjaxEventArgs e)
        {
            this.Label1.Text = "Server Time: " + DateTime.Now.ToLongTimeString();
        }
    </script>
    
    <!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 runat="server">
        <title>Coolite Toolkit Examples</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  3. #3

    RE: Listener problem in dynamics forms inherited from WebControl

    Thank you very much Geoffry,
    You example runs very well, but I'm using a WebControl, there is the problem.
    I think coolite does not take into account the [AjaxMethod] attribute when it is defined in a WebControl.
    I've debugged coolite and I've seen the function Coolite.Ext.Web.ScriptManager.GroupAjaxMethodsByNa mespace() only navigates userControls (not webControls).

    I need to understand a little more the behind the scenes. If I find something interesting I'll contact you.

    Again, thank you very much for you fast response.
  4. #4

    RE: Listener problem in dynamics forms inherited from WebControl

    Yep, at the moment, an [AjaxMethod] can only be defined in a Page, UserControl or WebService class.

    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] DirectEvent in WebControl
    By alliedwallet.com in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 21, 2011, 9:21 PM
  2. Replies: 13
    Last Post: Mar 31, 2011, 1:38 PM
  3. [CLOSED] Register javascript resource to inherited control
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 11, 2010, 8:24 PM
  4. [CLOSED] [1.0] WebControl and Ext controls
    By state in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 19, 2010, 6:51 AM
  5. Replies: 3
    Last Post: May 06, 2009, 3:04 PM

Posting Permissions