我對代碼中的這個問題感到困惑,並希望有人看到我在這裏失蹤的東西。這個工作的最上面部分是完美的,但是在下面的兩個其他類似字段上執行的相同基本代碼未能將值注入到文本框中,即使我已經刪除了所有可能的事情,我可以想到這可能會抑制功能加工。將值填入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