62,074
社区成员
发帖
与我相关
我的任务
分享
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function GetTotalAmount(textBox1, textBox2, textBox3)
{
document.getElementById(textBox3).value = parseFloat(document.getElementById(textBox1).value) + parseFloat(document.getElementById(textBox2).value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MyContent.aspx.cs" Inherits="MyContent" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</asp:Content>
public partial class MyContent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onchange", "GetTotalAmount('" + TextBox1.ClientID + "','" + TextBox2.ClientID + "','" + TextBox3.ClientID + "')");
TextBox2.Attributes.Add("onchange", "GetTotalAmount('" + TextBox1.ClientID + "','" + TextBox2.ClientID + "','" + TextBox3.ClientID + "')");
}
}