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:
Code:
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:
Code:
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)
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
Code:
<%@ 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>
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.
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.