application、viewstate、純HTML提交方式

來源:互聯網
上載者:User

標籤:sum   實體   添加   open   data   count   int   name   load   

Application - 全域公開變數組

存放位置:服務端

所有的訪問使用者都是訪問的同一個變數

聲明周期:永久

用法同session類似

 

viewstate-病例

因為http的無狀態性,需要記錄上一個頁面的狀態,因而需要一個viewstate記錄上一個頁面的狀態,然後返回成相應的內容

 

 

 

純HTML提交:

HTML介面:

要寫action與method:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title></title></head><body>    <form action="Default.aspx" method="get">        貨品名稱:<input type="text" name="t1"/><br />        貨品數量:<input type="text" name="t2"/><br />        單價:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="t3"/><br />        進貨時間:<input type="text" name="t4"/><br />        聯絡電話:<input type="text" name="t5"/><br />        倉庫號:&nbsp&nbsp&nbsp&nbsp      <select id="Select1" name="t6">          <option>g01</option>          <option>g02</option>          <option>g03</option>      </select>  <br />        <input type="submit" value="提交" />           </form></body></html>

實體類:

using System;using System.Collections.Generic;using System.Linq;using System.Web;/// <summary>/// goods 的摘要說明/// </summary>public class goods{    public goods()    {        //        // TODO: 在此處添加建構函式邏輯        //    }    public string goodsname { get; set; }    public string number { get; set; }    public string sprice { get; set; }    public DateTime intime { get; set; }    public string gtel { get; set; }    public string goodsbase { get; set; }}

資料訪問類:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.SqlClient;/// <summary>/// goodsdata 的摘要說明/// </summary>public class goodsdata{    SqlConnection conn = null;    SqlCommand cmd = null;    public goodsdata()    {        conn = new SqlConnection("server=.;database=data0928;user=sa;pwd=123");        cmd = conn.CreateCommand();    }    public bool insert(goods g)    {        bool ok = false;        int count = 0;        cmd.CommandText = "insert into goods values(@a,@b,@c,@d,@e,@f)";        cmd.Parameters.Clear();        cmd.Parameters.AddWithValue("@a",g.goodsname);        cmd.Parameters.AddWithValue("@b",g.number);        cmd.Parameters.AddWithValue("@c",g.sprice);        cmd.Parameters.AddWithValue("@d",DateTime.Now);        cmd.Parameters.AddWithValue("@e",g.gtel);        cmd.Parameters.AddWithValue("@f",g.goodsbase);        conn.Open();        count = cmd.ExecuteNonQuery();        conn.Close();        if (count > 0)        { ok = true; }        return ok;    }}

aspx介面:

using System;using System.Collections.Generic;using System.Data.SqlClient;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        goods g = new goods();        g.goodsname = Request["t1"];        g.number = Request["t2"];        g.sprice = Request["t3"];        g.intime = Convert.ToDateTime(Request["t4"]);        this.Title = g.intime.ToString();        g.gtel = Request["t5"];        g.goodsbase = Request["t6"];        bool ok = new goodsdata().insert(g);        if (ok)        {            Response.Write("<script>alert(‘添加成功‘)</script>");                    }    }}

 

application、viewstate、純HTML提交方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.