?
Solved

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

Posted on 2012-03-23
5
Medium Priority
?
149 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 750 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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