Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-23
5
Medium Priority
?
150 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

609 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