Ken Carter Ken Carter - 10 months ago 53
ASP.NET (C#) Question

Seeding values into asp:controls

I'm confused over this issue in my code and hoping that someone sees something that I'm missing here. The top part of this works perfectly but the same basic code being executed on two other similar fields directly below fails to inject the value into the text box even though I've striped off all possible things I could think of that might suppress the fuction from working.

I'm not getting any errors of any kind and when I debug it the values are being assigned as expected. Just nothing is showing up in the text boxes as I would expect.

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");

Anything anyone sees that would be helpful would be greatly appreciated. I've been glairing at it for the last several hours and getting no where.

Answer Source

Do you have a typo? uuname vs uname and uudate vs udate?

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");