The AsyncLabel is one of the only AsyncControl that provides you with over 9 built-in HtmlGenericControls. When utilizing RenderMode you can render the AsyncLabel as: H1-H6, Label, Span, Div, etc.
<%@ Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls" TagPrefix="dw" %> <dw:AsyncButton runat="server" ID="btVisible" CssClass="greyButton" OnClick="btVisible_Click" Text="Hide AsyncLabel" /> <br/> <dw:AsyncLabel runat="server" ID="lblMain" RenderMode="H4" CssClass="asyncLabel">This is an AsyncLabel.</dw:AsyncLabel> <p /> <dw:AsyncTextBox runat="server" ID="txtMain" EnableValidation="enabled" MaxLength="20" /> <dw:AsyncButton runat="server" ID="btMain" CausesValidation="true" OnClick="btMain_Click" CssClass="greyButton">Change AsyncLabel Text</dw:AsyncButton> <p /> <dw:AsyncButton runat="server" ID="btChangeCss" OnClick="btChangeCss_Click" CssClass="greyButton">Change the Label CSS class</dw:AsyncButton>
using System; using DelvingWare.AsyncControls; ... protected void btChangeCss_Click( object sender, AsyncEventArgs ae ) { if ( lblMain.Tag == null ) { // store the current CSS class lblMain.Tag = lblMain.CssClass; // change the css class for the AsyncLabel lblMain.CssClass = "lblMainClass"; } else { // reuse the stored CSS class lblMain.CssClass = lblMain.Tag as String; // clear the tag object lblMain.Tag = null; } } protected void btMain_Click( object sender, AsyncEventArgs ae ) { // ensure the page is valid if ( AsyncPage.IsValid ) { // update the AsyncLabel lblMain.Text = txtMain.Text; // focus the AsyncTextBox txtMain.Focus(); // select all the text within the AsyncTextBox txtMain.SelectAll(); } } protected void btVisible_Click( object sender, AsyncEventArgs ae ) { // change the visibility lblMain.Visible = !lblMain.Visible; // update the AsyncButton text if ( lblMain.Visible ) btVisible.Text = "Hide AsyncLabel"; else btVisible.Text = "Show AsyncLabel"; }
Imports System Imports DelvingWare.AsyncControls ... Protected Sub btChangeCss_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) If (lblMain.Tag = Nothing) Then ' store the current CSS class lblMain.Tag = lblMain.CssClass ' change the css class for the AsyncLabel lblMain.CssClass = "lblMainClass" Else ' reuse the stored CSS class lblMain.CssClass = CType(lblMain.Tag,String) ' clear the tag object lblMain.Tag = Nothing End If End Sub Protected Sub btMain_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' ensure the page is valid If AsyncPage.IsValid Then ' update the AsyncLabel lblMain.Text = txtMain.Text ' focus the AsyncTextBox txtMain.Focus ' select all the text within the AsyncTextBox txtMain.SelectAll End If End Sub Protected Sub btVisible_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' change the visibility lblMain.Visible = Not lblMain.Visible ' update the AsyncButton text If lblMain.Visible Then btVisible.Text = "Hide AsyncLabel" Else btVisible.Text = "Show AsyncLabel" End If End Sub
h4.asyncLabel { color: #777; font-family: verdana, arial, serif; font-size: 10pt; }