我正在使用母版和自定義控件在asp.net中開發示例應用程序我有包含兩個文本框和提交按鈕的用戶控件頁面,我只是從兩個文本boc並且只顯示到主網頁.. 這裏是代碼:如何將結果值傳遞給用戶控件的母版頁
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:TextBox ID="txtA" runat="server" />
<p>
</p>
<asp:TextBox ID="txtB" runat="server" />
<p />
<asp:Button ID="btn01" runat="server" Text="Submit" onclick="btn01_Click" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public delegate void SendMessageDelegate(string message);
public event SendMessageDelegate sendMsg;
protected void btn01_Click(object sender, EventArgs e)
{
decimal dec01 = Convert.ToDecimal(txtA.Text);
decimal dec02 = Convert.ToDecimal(txtB.Text);
decimal dectotal = dec01 + dec02;
if (sendMsg != null)
{
sendMsg(dectotal.ToString());
}
}
}
}
我覺得這個[thread] [1] mayb e可以幫助你。 [1]:http://stackoverflow.com/questions/15040421/access-a-control-in-user-control-and-master-page-value-in-user-control –
在什麼在你的母版頁週期的時刻你需要知道按鈕被點擊了嗎?在Page_Load事件裏面或者沒關係? – jdecuyper