我有一个表单,所有输入 type="text" 和 runat="server" 所以后面的代码可以看到它,它允许用户输入数据,然后如果从列表中选择,然后编辑相同的数据。填充表单进行编辑(工作正常)后,用户可以更改他们喜欢的任何字段并单击提交。代码可以正常工作,但我意识到没有任何更新。
通过代码进行调试后,我发现即使我在字段中键入了新文本,它仍然会发送在选择要编辑的记录时填充到字段中的原始文本。
此外,当通过 javascript 查看字段时,它们会按应有的方式反映字段中的当前文本,但在后面的代码中,它们会显示最初分配的内容。
代码:
从数据调用加载字段:
protected void LoadForm(int detailId)
{
List<Event> e = ado.GetEventDetails(detailId);
txtEventName.Value = e[0].eventName;
txtSponsOrg.Value = e[0].sponsOrg;
txtSponsOrgContactName.Value = e[0].sponsOrgContactName;
txtVenueName.Value = e[0].venueName;
txtStreetAddress.Value = e[0].venueAddress;
txtCity.Value = e[0].venueCity;
txtState.Value = e[0].venueState;
txtZip.Value = e[0].venueZip;
}
点击事件:
protected void SubmitForm_Click(object sender, EventArgs e)
{
SendCreateEvent();
}
以下应该在文本框中显示当前数据。调试时,无论我是否在字段中输入了新文本,它都会在从上述方法加载的框中显示原始文本。
private void SendCreateEvent()
{
//get user info
SessionManager sm = new SessionManager();
int userId = sm.UserApplicationID;
string userName = sm.UserLoginName;
string userFName = sm.UserFirstName;
string userLName = sm.UserLastName;
string userEmail = sm.UserEmailAddress;
//assign form field variables
string eventName = txtEventName.Value;
string sponsOrg = txtSponsOrg.Value;
string sponsOrgContact = txtSponsOrgContactName.Value;
string venueName = txtVenueName.Value;
string venueAddress = txtStreetAddress.Value;
string venueCity = txtCity.Value;
string venueState = txtState.Value;
string venueZip = txtZip.Value;
string detailId = Session["DetailId"].ToString();
ado.CreateEvent(detailId, userId, userName, userFName, userLName, userEmail,
eventName, sponsOrg, sponsOrgContact, venueName, venueAddress,
venueCity, venueState, venueZip)
}
编辑页面加载方法(请求):
protected void Page_Load(object sender, EventArgs e)
{
txtApprovedDate.Attributes.Add("readonly", "readonly");
txtEventDate.Attributes.Add("readonly", "readonly");
txtEventTimeStart.Attributes.Add("readonly", "readonly");
txtEventTimeEnd.Attributes.Add("readonly", "readonly");
int detailId = 0;
string loadForm = Session["LoadForm"].ToString();
if (Session["DetailId"].ToString() != "")
{
detailId = Convert.ToInt32(Session["DetailId"]);
}
if (loadForm == "true")
{
LoadForm(detailId);
}
}