Solved

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

Posted on 2006-07-11
9
289 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate report pulling data (links) from three tables 31 67
Summernote and form validation 10 192
Using querystring in a hyperlink 3 57
edit .asp files 5 32
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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