Solved

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

Posted on 2012-03-23
5
142 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now