applying partial rendering to a sample ASP.NET form : UpdatePanel « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
    Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script type="text/javascript">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>UpdatePanel in action</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1" /> 
        <div id="pageContent">       
            <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
                <ContentTemplate>
                        <tr>
                            <td>
                                <h2>Pick up an important date</h2>
            
                                        <asp:Calendar runat="server" ID="Calendar1" style="width:100%" 
                                            OnSelectionChanged="Calendar1_SelectionChanged" VisibleDate="5/1/2007" />
                                        <asp:TextBox runat="server" ID="TextBox1" />

                                    <br />
                                    <asp:Button runat="server" ID="Button1" Text="Save" OnClick="Button1_Click" />
                                    <asp:Label ID="Label1" runat="server" /> 
                            </td>

                            <td valign="top" style="border:solid 3px cyan;width:60%">
                                <h2>
                                    So [
                                    <asp:Label ID="Label3" runat="server" BackColor="cyan" />
                                    ] is important. Tell us why 
                                </h2>
                                <asp:TextBox runat="server" ID="TextBox2" 
                                        TextMode="MultiLine" Columns="50" Rows="10" />
                                <br />
                                <asp:Button runat="server" ID="Button2" Text="Save" OnClick="Button2_Click" />
                                <asp:Label ID="Label2" runat="server" />
                            </td>
                        </tr>
                </ContentTemplate>
            </asp:UpdatePanel>

        </div>
    </form>
</body>
</html>

File: Default.aspx.cs
using System;
using System.Web.Services;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            TextBox1.Text = Calendar1.VisibleDate.ToShortDateString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Picked up at " + DateTime.Now.ToShortTimeString();
        Label3.Text = TextBox1.Text;
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Text = "Saved at " + DateTime.Now.ToShortTimeString();
    }
}








3.31.UpdatePanel
3.31.1.Clock
3.31.2.UpdatePanel control is defined dynamically but constructing the tree programmatically
3.31.3.applying partial rendering to a sample ASP.NET form
3.31.4.RegisterAsyncPostBackControl method on the script manager class