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.ToStri ng("dd/MM/ yyyy")%>' runat="server"></asp:TextB ox>
anyone know what's wrong with this syntax??
<asp:TextBox id="txtWeekEnding" Text='<%# System.DateTime.Now.ToStri
anyone know what's wrong with this syntax??
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??
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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");
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtWeekEnding.Text = DateTime.Now.ToString("dd/
}
}
also check wherever you used txtWeekEnding reference. mainly in page_load.