我正在使用主控和自定义控件在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());
}
}
}
}
答案 0 :(得分:0)
您可以在您的用户控件中创建一个公共属性,并在您放置用户控件的网页中调用它。要传入主页,您可以执行以下操作:
((MasterPage)this.Master).SomeValue = SomeValue;