asp.net中updatepanel控制元件向外傳值
阿新 • • 發佈:2019-01-25
.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="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程式碼如下:
藉助JQuery實現資料在控制元件間傳遞。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); } }
效果如下: