• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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

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
jcampanali
Asked:
jcampanali
  • 4
  • 3
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
In your code behind:

    txtTo.Text = DateTime.Now.ToShortDateString();
0
 
jcampanaliAuthor Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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!

 
jcampanaliAuthor Commented:
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
 
alorentzCommented:
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
 
jcampanaliAuthor Commented:
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
 
alorentzCommented:
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
 
jcampanaliAuthor Commented:
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
 
alorentzCommented:
Glad to help...could try the Javascript ... just to see if it works <wink>...
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.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now