una paginetta semplice di prova
codice:
<%@ Page language="c#" Codebehind="WebForm12.aspx.cs" AutoEventWireup="false" Inherits="prova_web_c_charp.WebForm12" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm12</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<table>
<tr>
<td>Quantità:</td>
<td><asp:TextBox id="TextBox_quantita" runat="server" AutoPostBack="True"></asp:TextBox></td>
</tr>
<tr>
<td>Costo unitario:</td>
<td><asp:TextBox id="TextBox_costo_unitario" runat="server" AutoPostBack="True"></asp:TextBox></td>
</tr>
<tr>
<td>Totale:</td>
<td><asp:TextBox id="TextBox_totale" runat="server"></asp:TextBox></td>
</tr>
</table>
<asp:Button id="Button_salva" runat="server" Text="Salva"></asp:Button>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>
</body>
</HTML>
codice sottostante
codice:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace prova_web_c_charp
{
/// <summary>
/// Descrizione di riepilogo per WebForm12.
/// </summary>
public class WebForm12 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox_quantita;
protected System.Web.UI.WebControls.TextBox TextBox_costo_unitario;
protected System.Web.UI.WebControls.Button Button_salva;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox_totale;
private void Page_Load(object sender, System.EventArgs e)
{
// Inserire qui il codice utente necessario per inizializzare la pagina.
}
#region Codice generato da Progettazione Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: questa chiamata è richiesta da Progettazione Web Form ASP.NET.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
this.TextBox_quantita.TextChanged += new System.EventHandler(this.TextBox_quantita_TextChanged);
this.TextBox_costo_unitario.TextChanged += new System.EventHandler(this.TextBox_costo_unitario_TextChanged);
this.Button_salva.Click += new System.EventHandler(this.Button_salva_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button_salva_Click(object sender, System.EventArgs e)
{
this.Label1.Text = "Totale: " + this.TextBox_totale.Text;
}
private void TextBox_quantita_TextChanged(object sender, System.EventArgs e)
{
try
{
double totale = double.Parse(this.TextBox_costo_unitario.Text) * double.Parse(this.TextBox_quantita.Text);
this.TextBox_totale.Text = totale.ToString();
}
catch (Exception ex)
{
;
}
}
private void TextBox_costo_unitario_TextChanged(object sender, System.EventArgs e)
{
try
{
double totale = double.Parse(this.TextBox_costo_unitario.Text) * double.Parse(this.TextBox_quantita.Text);
this.TextBox_totale.Text = totale.ToString();
}
catch (Exception ex)
{
}
}
}
}