0

我正在使用主控件和自定义控件在 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());
            }


        }
    }
}
4

1 回答 1

0

您可以在您的用户控件中创建一个公共属性,并在您放置用户控件的网页中调用它。要传递到母版页,您可以这样做:

((MasterPage)this.Master).SomeValue = SomeValue;
于 2013-07-23T15:03:22.190 回答