Hello everyone,
First let me say thanks to anyone that post an answer to my question.
Let me explain the what I am trying to do. The code below is an example and try to keep all answers within the five pages that I have posted. I did not want to post the complex version of my code because I think if this gets solved then others can use the simplest version of this question and apply it to their solutions.
I have tried and tried but could not find an elegant way of doing this. Any ideas? Below is the code.
**MasterPage.ma ster**
**Home.aspx**
**Home.aspx.cs* *
**WebUserContro l.ascx**
**WebUserContro l.ascx.cs**
Please help and thanks you!
CroCrew~
First let me say thanks to anyone that post an answer to my question.
Let me explain the what I am trying to do. The code below is an example and try to keep all answers within the five pages that I have posted. I did not want to post the complex version of my code because I think if this gets solved then others can use the simplest version of this question and apply it to their solutions.
- I want a user control (WebUserControl .ascx) on a web page (Home.aspx) that uses a master page (MasterPage.mas ter).
- There is a button on the user control (WebUserControl .ascx) that will do a calculation within the code behind of the user control (WebUserControl .ascx.cs).
- There is a “Label” on the web page (Home.aspx) that I want updated to show the calculated value from “TextBox3” in the user control (WebUserControl .ascx) after the button in the user control (WebUserControl .ascx) has been clicked.
I have tried and tried but could not find an elegant way of doing this. Any ideas? Below is the code.
**MasterPage.ma ster**
Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
Add it up!<br />
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" %>
<%@ Register TagPrefix="Math" TagName="AddControl" Src="~/WebUserControl.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Label">Display the value from control here!</asp:Label><br />
<Math:AddControl ID="CoolMath" runat="server" />
</asp:Content>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:TextBox ID="TextBox1" runat="server" /> + <asp:TextBox ID="TextBox2" runat="server" /> = <asp:TextBox ID="TextBox3" runat="server" />
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Int32 Val1 = Int32.Parse(TextBox1.Text.ToString());
Int32 Val2 = Int32.Parse(TextBox2.Text.ToString());
TextBox3.Text = (Val1 + Val2).ToString();
}
}
Please help and thanks you!
CroCrew~
Comment