ASP.NET AJAX入门系列(4):使用UpdatePanel控件(一)

豆豆网   技术应用频道   2007年11月21日  【字号: 收藏本文

本文详细介绍ASP.NET AJAX入门系列(4):使用UpdatePanel控件(一)

  事件代码:

  <script runat="server">
  void DropDownSelection_Change(Object sender, EventArgs e)
  {
  Calendar1.DayStyle.BackColor =
  System.Drawing.Color.FromName(ColorList.SelectedItem.Value);
  }
  </script>

  四.ContentTemplateContainer属性

  如果要使用编程的手法去设置UpdatePanel中的内容,需要创建一个UpdatePanel,并且添加控件到ContentTemplateContainer,而不能直接添加控件到ContentTemplate,如果想直接设置ContentTemplate,则需要编写一个自定义的Template,并去实现位于System.Web.UI命名空间下的接口ITemplate。看一个简单的来自于官方网站的例子:

<%@ Page Language="C#" %>
  <script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
  UpdatePanel up1 = new UpdatePanel();
  up1.ID = "UpdatePanel1";
  up1.UpdateMode = UpdatePanelUpdateMode.Conditional;
  Button button1 = new Button();
  button1.ID = "Button1";
  button1.Text = "Submit";
  button1.Click += new EventHandler(Button_Click);
  Label label1 = new Label();
  label1.ID = "Label1";
  label1.Text = "A full page postback occurred.";
  up1.ContentTemplateContainer.Controls.Add(button1);
  up1.ContentTemplateContainer.Controls.Add(label1);
  Page.Form.Controls.Add(up1);
  }
  protected void Button_Click(object sender, EventArgs e)
  {
  ((Label)Page.FindControl("Label1")).Text = "Panel refreshed at " +
  DateTime.Now.ToString();
  }
  </script>
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head id="Head1" runat="server">
  <title>UpdatePanel Added Programmatically Example</title>
  </head>
  <body>
  <form id="form1" runat="server">
  <div>
  <asp:ScriptManager ID="TheScriptManager"
   runat="server" />
  </div>
  </form>
  </body>
  </html>

来源:TerryLee    责编:豆豆技术应用

正在加载评论...