关于取值的问题

开发一个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");
}

发现了一个问题,就是所有控件的值只能取到我在页面初始化时给他加载的值,而取不到我在里面输入的最新的值,怀疑是不是微软的东西有错误,大家有没有遇到这个问题的给我说说,谢谢了。

posted on 2007-09-19 09:03  JesseZhao  阅读(862)  评论(16编辑  收藏  举报

导航