Custom Inherited Extension Control (LinkButton)

Modified: 2008/10/06 17:34 by stians - Categorized as: Tutorials
In this tutorial we will create a simple extension by inheriting from an existing Ajax Control like LinkButton

Edit

Creating an extended Ajax LinkButton

To create an Ajax LinkButton Extension control which will end up looking like this...

Ajax LinkButton Extension

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... ;)"; }

ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.