正文

ASP.NET AJAX练习一2007-08-03 16:51:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/mimengjiangnan/28179.html

分享到:

页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title></head><body>    <form id="form1" runat="server">    <div>        <asp:ScriptManager ID="ScriptManager1" runat="server">        </asp:ScriptManager>    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>       </form></body></html>   后台代码: using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls; public partial class Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        ScriptManager1.RegisterAsyncPostBackControl(Button1);  //指定Button1是异步刷新控件        UpdatePanel up = new UpdatePanel();        up.ID = "up1";        up.UpdateMode = UpdatePanelUpdateMode.Conditional; //指定更新模式        Label lbl = new Label();        lbl.ID = "lbl1";        lbl.Text = "www";        up.ContentTemplateContainer.Controls.Add(lbl);        up.ContentTemplateContainer.Controls.Add(TextBox1);        Page.Form.Controls.Add(up);    }    protected void Button1_Click(object sender, EventArgs e)    {        ((Label)Page.Form.FindControl("lbl1")).ForeColor = System.Drawing.Color.Red;        TextBox1.Text = "我有名字了";        ((UpdatePanel)Page.Form.FindControl("up1")).Update();        ScriptManager.RegisterClientScriptBlock(Page, GetType(), "Open", "alert('Server')", true);    }}

阅读(2534) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册