關於取值的問題

來源:互聯網
上載者:User

開發一個NBear作為基礎架構的網站的時候,遇到了一個很變態的問題,自己苦思加從網上都沒有找到相關的解法,只好發帖到首頁來求解,真的很急的一個東西,希望大家體諒。

這個主要問題就是我有一個更新的頁面產品的頁面,在介面載入的時候用下面的代碼初始化的頁面上面控制項的值:

protected void Page_Load(object sender, EventArgs e)
{
    SureLogin();
    int id = GetIntParam("id", 0);
    if (id == 0)
    {
        Response.Redirect("managegoods.aspx");
    }
    else
    {
        dsCategory.Filter(WhereClip.All);
        ddlCategory.DataBind();
        Goods aGoods =
            Gateways.SdaiBuy.Find<Goods>(id);
        ddlCategory.SelectedValue = aGoods.GoodsCategory.ID.ToString();
        tbMarketing.Text = aGoods.Marketing.ToString ();
        tbName.Text = aGoods.Name;
        tbPrice.Text = aGoods.Price;
        tbStock.Text = aGoods.Stock.ToString();
        weIntro.Text = aGoods.Content;
    }

}

然後在我更新按鈕裡面寫了下面的代碼更新資料庫:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //上傳圖片
    bool fileOK = false;
    string path = Server.MapPath("~/UpFile/");
    string picname = string.Empty;
    if (FileUploadPic.HasFile)
    {
        string fileExtension = System.IO.Path.GetExtension(FileUploadPic.FileName).ToLower();
        string[] allowExtensions ={ ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
        for (int i = 0; i < allowExtensions.Length; i++)
        {
            if (fileExtension == allowExtensions[i])
            {
                fileOK = true;
            }
        }
    }
    if (fileOK)
    {
        try
        {
            FileUploadPic.SaveAs(path + FileUploadPic.FileName);
            picname = System.IO.Path.GetFileName(FileUploadPic.PostedFile.FileName);
        }
        catch (Exception ex)
        {
            Label1.Text = "失敗";
        }
    }

    //將商品記錄更改加入資料庫
    int id = GetIntParam("id", 0);
    Goods aGoods =
           Gateways.SdaiBuy.Find<Goods>(id);
    aGoods.Marketing = Convert.ToInt32 ( tbMarketing.Text);
    aGoods.Name = tbName.Text;
    if (picname != string.Empty)
    {
        aGoods.PicPath = "upfile/" + picname;
    }
    aGoods.Price = Server.HtmlEncode ( tbPrice.Text.Trim ());
    aGoods.Stock = Convert.ToInt32 (tbStock.Text);
    aGoods.Content = weIntro.Text;

    Gateways.SdaiBuy.Save<Goods>(aGoods);
    Category aCategory = Gateways.SdaiBuy.Find<Category>(Convert.ToInt32 (ddlCategory.SelectedValue) );
    aCategory.ShopGoods.Add(aGoods);

    Gateways.SdaiBuy.Save<Category>(aCategory);
    Response.Redirect("manageGoods.aspx");
}

發現了一個問題,就是所有控制項的值只能取到我在頁面初始化時給他載入的值,而取不到我在裡面輸入的最新的值,懷疑是不是微軟的東西有錯誤,大家有沒有遇到這個問題的給我說說,謝謝了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.