Link to home
Start Free TrialLog in
Avatar of Lorna70
Lorna70

asked on

Setting value of TextBox to default to today's date - not working on some forms

Hi In some forms my code works but on one form, nothing appears in the TextBox at all - totally confused by this.  My code is:

<asp:TextBox id="txtWeekEnding" Text='<%# System.DateTime.Now.ToString("dd/MM/yyyy")%>' runat="server"></asp:TextBox>

anyone know what's wrong with this syntax??
Avatar of Rose Babu
Rose Babu
Flag of India image

Can you check once for the txtWeekEnding.Text = "" in the code behind file?

also check wherever you used txtWeekEnding reference. mainly in page_load.
Avatar of Lorna70
Lorna70

ASKER

Thanks - good point but I've checked my code behind and the only reference I have is:

string endDate = txtWeekEnding.Text;

This obviously just retrieves text user has entered so doesn't change the value set.  Any more ideas??
ASKER CERTIFIED SOLUTION
Avatar of Rose Babu
Rose Babu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or Try to place the databind function in page_load alone will work.
<asp:TextBox id="txtWeekEnding" Text='<%# System.DateTime.Now.ToString("dd/MM/yyyy")%>' runat="server"></asp:TextBox>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

          Page.DataBind(); 

End Sub

Open in new window

Avatar of Lorna70

ASKER

I still don't understand why I couldn't do it on the Text= but the following worked:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
               txtWeekEnding.Text = DateTime.Now.ToString("dd/MM/yyyy");
        }
    }