我的网页上有4个文本框,其中一个是使用javascript日历控件填充的......问题是所有这些文本框在回发后都会丢失它们的值(单击一个asp.net按钮控件)。文本框不是只读的,所以我无法弄清楚为什么会这样......请帮助......并且谢谢
protected void Page_Load(object sender, EventArgs e)
{
BindProdTopDetails();
BindProdTable();
// BindProdComment();
}
protected void BtnProdUpdate_Click(object sender, EventArgs e)
{
//saveProdDetails();
bool success = saveProdDetails();
if (success)
{
string strScript96 = "<script language=JavaScript>";
strScript96 += "javascript:alert('Update Successful');";
strScript96 += "</script>";
if (!ClientScript.IsStartupScriptRegistered("clientScript"))
ClientScript.RegisterClientScriptBlock(this.GetType(), clientScript", strScript96);
}
}
public bool saveProdDetails()
{
string prodLine = DDProdLine.SelectedValue;
string stock1 = DDMaterial.SelectedValue;
string stock2 = TextBoxMaterial.Text.Trim().ToString();
string supplier = TextBoxSupplier.Text.Trim().ToString();
string billet = RBBillet.SelectedValue;
string matTime1 = TextBoxMatTime.Text.Trim().ToString();
string matTime2 = DDMatTime.SelectedValue;
string prodTime1 = TextBoxProdTime.Text.Trim().ToString();
string prodTime2 = DDProdTime.SelectedValue;
string shipTime1 = TextBoxShipTime.Text.Trim().ToString();
string shipTime2 = DDShipTime.SelectedValue;
CultureInfo cultureInfo = CultureInfo.CurrentCulture;
string format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString();
string cmr = cmrDue.Value.ToString();
string kc = kcDue.Value.ToString();
string x = cmr.Substring(3, 2);
string y = cmr.Substring(0, 2);
string z = cmr.Substring(6, 4);
string x1 = kc.Substring(3, 2);
string y1 = kc.Substring(0, 2);
string z1 = kc.Substring(6, 4);
string finalCmr = x + "/" + y + "/" + z;
string finalKC = x1 + "/" + y1 + "/" + z1;
DateTime dt = DateTime.ParseExact(finalCmr, format, cultureInfo);
DateTime cr = DateTime.ParseExact(finalKC, format, cultureInfo);
string custDate = dt.ToString("dd/mm/yyyy");
string kcDate = cr.ToString("dd/mm/yyyy");
string id = Request.QueryString["id"];
bool success = true;
TextBoxProdComment1.Text = stock2 + "," + supplier + matTime1 + "," + prodTime1 + "," + shipTime1 + "," + custDate
+ "," + kcDate;
try
{
success = CRTopButtons.SaveProdTable(id, prodLine, stock1, supplier, billet, matTime1, matTime2, prodTime1,
prodTime2, shipTime1, shipTime2, custDate, kcDate);
}
catch (Exception e)
{
System.Diagnostics.Trace.Write(e.StackTrace);
}
return success;
}
答案 0 :(得分:1)
使用示例代码进行更新,同意IsPostBack标志。
if (!IsPostBack)
{
BindProdTopDetails();
BindProdTable();
// BindProdComment();
}
答案 1 :(得分:1)
我怀疑您是否在页面加载事件中分配/清除文本框值...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Text = "";
}
}
你需要在执行之前放置条件if (!Page.IsPostBack)