IsPostBack 解决不能把asp:text的值传导服务器端的问题

此博客展示了ASP.NET更新产品信息的代码。包含多个命名空间引用,定义了UpdateProduct类,在Page_Load方法中获取产品信息并初始化页面,在Button1_Click方法中更新产品信息,涉及产品名称、数量、价格等内容。

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;
using wztj.page.product.model;
using wztj.page.product.code;
using wztj.page.category.code;
using System.Text;


namespace wztj.page.rfq
{
 /// <summary>
 /// Summary description for UpdateProduct.
 /// </summary>
 public class UpdateProduct : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox name;
  protected System.Web.UI.WebControls.TextBox manufacture;
  protected System.Web.UI.WebControls.TextBox quantity;
  protected System.Web.UI.WebControls.TextBox unit;
  protected System.Web.UI.WebControls.TextBox classType;
  protected System.Web.UI.WebControls.TextBox status;
  protected System.Web.UI.WebControls.TextBox description;
  protected System.Web.UI.WebControls.TextBox quotedPrice;
  protected System.Web.UI.WebControls.DropDownList DropDownList1;
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.HtmlControls.HtmlForm Form1;
  protected System.Web.UI.HtmlControls.HtmlInputText expirationDate;
  protected string ProductID;
  protected Product product;
  protected string username;
  protected string productType;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   ProductID = this.Request.QueryString.Get("ProductID");
   username = Session["username"].ToString();
   ProductManager productManager = new ProductManager();
   product = productManager.getProductByProductID(ProductID);
   if(!this.IsPostBack)
   {
    this.name.Text = product.Name;
    this.manufacture.Text = product.Manufacture;
    this.quantity.Text = product.Quantity.ToString();
    this.unit.Text = product.Unit;
    this.classType.Text = product.ClassType;
    this.status.Text = product.Status;
    this.description.Text = product.Description;
    this.quotedPrice.Text = product.QuotedPrice.ToString();
    this.expirationDate.Value = product.ExpirationDate;
    CategoryManager categoryManager = new CategoryManager();
    DataTable dt = categoryManager.getRootCategories();
    this.DropDownList1.DataSource=dt;
    this.DropDownList1.DataTextField = "categoryName";
    this.DropDownList1.DataBind();
   }
   this.productType = product.ProductType;
   // Put user code to initialize the page here
  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void Button1_Click(object sender, System.EventArgs e){
   ProductManager productManager =new ProductManager();
   Product product = productManager.getProduct(username,this.name.Text,
    this.manufacture.Text,Double.Parse(this.quantity.Text),this.unit.Text,this.classType.Text,
    this.status.Text,this.description.Text,Double.Parse(this.quotedPrice.Text),this.expirationDate.Value,
    this.DropDownList1.SelectedItem.Text,productType);
   product.Id=long.Parse(ProductID);
   productManager.updateProduct(product);
  }
 }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值