Solved

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

Posted on 2012-03-23
5
146 Views
Last Modified: 2012-03-26
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??
0
Comment
Question by:Lorna70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37756396
Can you check once for the txtWeekEnding.Text = "" in the code behind file?

also check wherever you used txtWeekEnding reference. mainly in page_load.
0
 

Author Comment

by:Lorna70
ID: 37756426
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??
0
 
LVL 16

Accepted Solution

by:
Rose Babu earned 250 total points
ID: 37756448
Hmm, ok.

can you try to set txtWeekEnding.Text = Date.Now.ToString("dd/MM/yyyy") in your page_Load.?

then check if it is set the date in the textbox.

also do you use any javascript to set/clear the textbox value?
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37756517
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

0
 

Author Closing Comment

by:Lorna70
ID: 37769865
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");
        }
    }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question