我对代码中的这个问题感到困惑,并希望有人看到我在这里失踪的东西。这个工作的最上面部分是完美的,但是在下面的两个其他类似字段上执行的相同基本代码未能将值注入到文本框中,即使我已经删除了所有可能的事情,我可以想到这可能会抑制功能加工。将值填入asp:控件
我没有收到任何类型的错误,当我调试它时,数值按预期分配。就像我所期望的那样,文本框中没有显示任何内容。
protected void Page_Load(object sender, EventArgs e)
{
<%-- This part works fine --%>
TextBox uname = (TextBox)AddItemFv.Row.FindControl("SubmitByTbx");
if (uname != null)
uname.Text = Session["RegUser"].ToString();
TextBox udate = (TextBox)AddItemFv.Row.FindControl("SubmitDTTbx");
if (udate != null)
udate.Text = DateTime.Now.ToString("MM/dd/yyyy");
<%-- This part Fails to stuff the values into the TextBoxes --%>
TextBox uuname = (TextBox)AddItemFv.Row.FindControl("AssetEnteredByTextBox");
if (uname != null)
uname.Text = Session["RegUser"].ToString();
TextBox uudate = (TextBox)AddItemFv.Row.FindControl("AssetEnteredTextBox");
if (udate != null)
udate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
任何人都认为这将是有益的将不胜感激。在过去的几个小时里,我一直在看它,并没有去哪里。基于响应
最终的解决方案提供如下所示:
protected void Page_Load(object sender, EventArgs e)
{
TextBox uname = (TextBox)AddItemFv.Row.FindControl("SubmitByTbx");
if (uname != null)
uname.Text = Session["RegUser"].ToString();
TextBox udate = (TextBox)AddItemFv.Row.FindControl("SubmitDTTbx");
if (udate != null)
udate.Text = DateTime.Now.ToString("MM/dd/yyyy");
TextBox uuname = (TextBox)AddItemFv.Row.FindControl("AssetEnteredByTextBox");
if (uuname != null)
uuname.Text = Session["RegUser"].ToString();
TextBox uudate = (TextBox)AddItemFv.Row.FindControl("AssetEnteredTextBox");
if (uudate != null)
uudate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
什么是你的.aspx文件看起来像2的ID名称不工作可以显示标记 – MethodMan