?
Solved

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

Posted on 2006-07-11
9
Medium Priority
?
294 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
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 informatio…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…

762 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