Solved

Make Today's Date show as the Default Value of ASP Textbox

Posted on 2006-07-11
9
291 Views
Last Modified: 2012-06-27
I have From and To dates that are passed to Crystal Reports as date parameters.  Using this code:
<asp:textbox id="txtFrom" text="01-01-2006" runat="server" MaxLength="10" CssClass="input" Width="96px"></asp:textbox>

I have January 1, 2006 as the default From date already displayed when the user clicks the Reports tab.

How do I get today's date to display as the Default Value for my txtTo textbox?
0
Comment
Question by:jcampanali
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17085409
In your code behind:

    txtTo.Text = DateTime.Now.ToShortDateString();
0
 
LVL 4

Author Comment

by:jcampanali
ID: 17085652
need more detail

The asp page is ReportMenu.aspx.
Our India programmers wrote this page.
In the top of the document, I see where it says CodeBehind="ReportMenu.aspx.vb", but this file does not exist.

Next?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17085968
It has to exist otherwise the page won't compile.

With Source view active, go to the View menu and select Code. That should take you to the code-behind.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:jcampanali
ID: 17086009
I do not have VB or VS.NET, I am on the server where the pages are hosted and just making changes to the file there.
0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 17087100
Add this:

<script runat="server">
    Sub Page_Load(sender as Object, e as EventArgs)
       If Not Page.IsPostBack then
           txtTo.Text = DateTime.Now.ToString("d")  '<--------NEW LINE
       End If
    End Sub
</script>

If you already have this sub...

Sub Page_Load(sender as Object, e as EventArgs)

just add the new line in the middle...
0
 
LVL 4

Author Comment

by:jcampanali
ID: 17088627
All I have is ReportMenu.aspx  I cannot access CodeBehind

I don't see where I can add these lines.  I tried several places and they do not change the Page_Load behavior.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17090131
The code I gave can go right in the page...but if there is codebehind, I guess it won't work.

Try Javascript then.


<script>
dt=new Date(intYear,month-1,day);
dt=dt.toString().replace(/\d{2}\:\d{2}\:\d{2}[ \w]*/,' ');
document.getElementById('txtTo').value = dt;
</script>


Put that at the bottom of the page.
0
 
LVL 4

Author Comment

by:jcampanali
ID: 17091164
For being a big help, alorentz gets the points.  i know the code would work if I had access to code behind.  India fixed the "to" date for me overnight.

Regards
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17091348
Glad to help...could try the Javascript ... just to see if it works <wink>...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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