首页 > 代码库 > asp.net中updatepanel控件向外传值

asp.net中updatepanel控件向外传值

.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdatePanel控件传值.aspx.cs" Inherits="UpdatePanel控件传值" %>


<!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>
    <script src=http://www.mamicode.com/"JS/jquery-1.8.3.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p><%=DateTime.Now.ToString() %></p>
    您选择的日期为:
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <p><%=DateTime.Now.ToString() %></p>
        <asp:Calendar ID="Calendar1" runat="server" 
            onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UpdatePanel控件传值 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        string _cl = Calendar1.SelectedDate.ToLongDateString();
        string _script = "$('#TextBox1').val('"+_cl+"')";
        ScriptManager.RegisterStartupScript(this,this.GetType(),"",_script,true);
    }
}
借助JQuery实现数据在控件间传递。

效果如下:



asp.net中updatepanel控件向外传值