我正在創建一個WebForm,其中提供了啓用和禁用文本框的功能。但是,當我在TextBox中輸入值並禁用它時。我無法將TextBox值保存在數據庫中。每當代碼嘗試保存該值時,都會在其中獲取一個空值,因此它會存儲一個空值。當我不禁用TextBox時,那麼該值將被成功存儲在表中。下面是關於它的一些代碼...如何從使用C#的WebForm中禁用的文本框中獲取值
protected void btnCreateSubAcct_Click(object sender, EventArgs e)
{
int subAccountID = 0;
try
{
if (Page.IsValid)
{
subAccountID = SaveUpdateSubAccount();
if (string.IsNullOrEmpty(HiddenFieldSubAccntID.Value))
{
SessionHandler.Set(SessionHandler.SubAccountIDKey, subAccountID);
Response.Redirect("~/newaccountwelcome");
}
else
{
lblDialogMessage.Text = "Subaccount updated successfully!";
modalPage.Visible = true;
SetFocus(btnOK.ClientID);
}
}
}
catch (ThreadAbortException)
{
}
catch (Exception ex)
{
_log.Error("Error Occured While Creation of SubAccount.", ex);
throw;
}
}
private int SaveUpdateSubAccount()
{
SubAccount objSubAccount = null;
if (!string.IsNullOrEmpty(HiddenFieldSubAccntID.Value) && !HiddenFieldSubAccntID.Value.Equals("0"))
{
objSubAccount = SubAccount.GetSubAccount(Convert.ToInt32(HiddenFieldSubAccntID.Value));
}
if (objSubAccount == null)
{
objSubAccount = new SubAccount();
objSubAccount.CreatedByUser = SessionHandler.CurrentUser.UserID;
}
objSubAccount.FBO1FirstName = txtFBO1FirstName.Text.Trim();
objSubAccount.FBO1MiddleInitial = txtFBO1MiddleName.Text.Trim();
objSubAccount.FBO1LastName = txtFBO1LastName.Text.Trim();
objSubAccount.FBO1AccountTitling = txtFbo1AccountTitling.Text.Trim();
objSubAccount.FBO1TaxIDType = fbo1RadioButtonList.SelectedItem.Value;
objSubAccount.FBO1TaxID = Helpers.GetUnFormattedTIN(txtFbo1TaxId.Text.Trim());
}
//under the class SubAccount, the information is getting stored in the database
每當我試圖保存文本FBO1TaxID的價值,當它處於禁用狀態,這個文本框下的值是空的。
如何將TextBox的值保存在數據庫表中的禁用模式下?請幫忙!
但是,如何從數據庫表中獲取禁用文本框中的值? – Yash
我想你可以先啓用它,設置值/文本,然後禁用它。它應該設置文本。但我不確定。 – urlreader