如何获取文本框事件的值,尽管它在页面加载函数中被赋值

本文关键字:加载 函数 赋值 取文本 何获 事件 | 更新日期: 2023-09-27 18:22:36

这是页面加载功能代码

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //DropDownList Binding through bussiness logic
            Bussiness_logic.DropDownList_Bind(DDL_U, "SHORT_DESC", "UNIT_CODE", "UNIT_SOURCE");
            Bussiness_logic.DropDownList_Bind(DDL_Branch, "TYPE_DESC", "TYPE_CODE", "BRANCH_SOURCE");
        }
        if (Request.QueryString["File"] != null)
            {
                string fileNo = Request.QueryString["File"].ToString();
                Bussiness_logic.OpenConnection();
                SqlCommand com = new SqlCommand("LINK_DATA", Bussiness_logic.con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@FILE", fileNo);
                SqlDataReader dtr = com.ExecuteReader();
                if (dtr.HasRows)
                {
                    dtr.Read();
                    {
                        TxtFile.Text = dtr["FILE_NO"].ToString();
                        DDL_Branch.SelectedItem.Value = dtr["TYPE_DESC"].ToString();
                        TxtSub.Text = dtr["SUBJECT"].ToString();
                        DDL_U.SelectedItem.Value = dtr["SHORT_DESC"].ToString();
                    }
                }
                Bussiness_logic.CloseConnection();
                Label1.Text = "";
            }
      }


我的问题是,它没有更新数据,它只获取页面加载函数

如何获取文本框事件的值,尽管它在页面加载函数中被赋值

时填充的值

可能您没有使用Page.IsPostback属性。在页面生命周期中,Page_Load将在按钮的Click事件处理程序之前执行。尝试将从SQL中获取值的代码包装为:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        // get values from SQL
    }
}