In the origin control, you implement the event of delegate
, post the message with the MessageHandler
at the click of the button. The source control must have a public method to handle this message and you bind both to parent
where controls were included, see the example below.
Dadospagamento.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DadosPagamento.ascx.cs" Inherits="WebApplication.Forms.DadosPagamento" %>
<h1>Dados de Pagamento</h1>
<asp:TextBox ID="txtNumeroPropostaOrigem" runat="server" />
<asp:Button ID="btnConfirmar" runat="server" Text="Confirmar" OnClick="btnConfirmar_Click"/>
Dadospagamento.ascx.Cs
public delegate void MessageHandler(string codigoProposta);
public partial class DadosPagamento : System.Web.UI.UserControl
{
public event MessageHandler EnviarProposta;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnConfirmar_Click(object sender, EventArgs e)
{
EnviarProposta(txtNumeroPropostaOrigem.Text);
txtNumeroPropostaOrigem.Text = string.Empty;
}
}
Dadoscobranca.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DadosCobranca.ascx.cs" Inherits="WebApplication.Forms.DadosCobranca" %>
<h1>Dados de Cobrança</h1>
<asp:TextBox ID="txtNumeroPropostaDestino" runat="server"></asp:TextBox>
Dadoscobranca.ascx.Cs
public partial class DadosCobranca : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void CarregarProposta(string codigoProposta)
{
txtNumeroPropostaDestino.Text = codigoProposta;
}
}
Registration.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CadastroProposta.aspx.cs" Inherits="WebApplication.Forms.CadastroProposta" %>
<%@ Register Src="~/DadosPagamento.ascx" TagPrefix="ucPagamento" TagName="DadosPagamento" %>
<%@ Register Src="~/DadosCobranca.ascx" TagPrefix="ucCobranca" TagName="DadosCobranca" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ucPagamento:DadosPagamento runat="server" id="DadosPagamento" />
</div>
<hr />
<div>
<ucCobranca:DadosCobranca runat="server" id="DadosCobranca" />
</div>
</form>
</body>
</html>
Cadastroproposta.aspx.Cs
public partial class CadastroProposta : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DadosPagamento.EnviarProposta += m => DadosCobranca.CarregarProposta(m);
}
}
See if this is what you were looking for. And edit your question by presenting the actual code of your controls, this makes it easier to understand the problem and to come up with an answer to your question
– Leandro Angelo