In this tutorial we will create a simple extension by inheriting from an existing Ajax Control like LinkButton
EditCreating an extended Ajax LinkButton
To create an Ajax LinkButton Extension control which will end up looking like this...
LinkButton C# Code
// A complete Ajax WebControl created with less than 10 lines of code
public class MyCoolLinkButton : Gaia.WebWidgets.LinkButton, Gaia.WebWidgets.IAjaxControl
{
public void RenderControlHtml(Gaia.WebWidgets.HtmlFormatting.XhtmlTagFactory create)
{
using (Gaia.WebWidgets.HtmlFormatting.Tag link =
create.A(ClientID, CssClass, "javascript:Gaia.LinkButton.fooBar();"))
{
Style"border" = "dashed 2px Black";
Style"background-color" = "#eee";
Style"padding" = "5px";
Css.SerializeAttributesAndStyles(this, link);
link.WriteContent(Text);
}
}
}
ASPX Markup ( Just a blank Page )
<%@ Page
Language="C#"
ClassName="_Default" %>
<%@ Register
Assembly="Gaia.WebWidgets"
Namespace="Gaia.WebWidgets"
TagPrefix="gaia" %>
Ajax Sample
C# Codebehind
protected void Page_Load(object sender, EventArgs e)
{
MyCoolLinkButton btn = new MyCoolLinkButton();
btn.Text = "Click me";
btn.Click += clicked;
Form.Controls.Add(btn);
}
protected void clicked(object sender, EventArgs e)
{
(sender as MyCoolLinkButton).Text = "Thank you for clicking me... ;)";
}