Main Topics
Browse All TopicsI have an asp web form using vb. I would like to populate a text field automatically with the current date. The code i am using is listed below.
I have tried a couple of things without success. Essentially I am hoping to not have to use javascript -- hoping that this can be handled strictly with asp, vb, or both.
Disclaimer: I am a total asp newbie -- this is my first attempt at creating an asp web form that will read and write from a database.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for the replies.
I have attempted ArachnidCreations' solution previously as it seemed to make the most sense -- but all that does is display "<%=Date()%>" in the text field when viewing the page in a browser.
As for alainbryden's solution: I posted the code i used below and when viewing the page in a browser I get the following error message:
==========================
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30203: Identifier expected.
Source Error:
Line 3: Inherits System.Web.UI.Page
Line 4:
Line 5: Sub
Line 6:
Line 7: Dim as d_today
Source File: U:\My Documents\Visual Studio 2008\WebSites\WebSite4\Def
==========================
HA!
Here is the next error message:
Compiler Error Message: BC30108: 'Date' is a type and cannot be used as an expression.
Source Error:
Line 5: Sub JasonsSub()
Line 6: Dim d_today
Line 7: d_today=Date
Line 8: Response.Write(d_today)
Line 9: End Sub
Source File: U:\My Documents\Visual Studio 2008\WebSites\WebSite4\Def
Yeah -- tried that -- error message is below, though. What could the problem be? I am using VS2008, but i dont think that should matter -- i mean, its just code that counts, right?
Not sure why this is so difficult -- i have been coding in PHP for a while now and something as simple as displaying the current date is so easy!
==========================
Compiler Error Message: BC30108: 'Date' is a type and cannot be used as an expression.
Source Error:
Line 5: Sub JasonsSub()
Line 6: Dim d_today
Line 7: d_today=Date()
Line 8: Response.Write(d_today)
Line 9: End Sub
Source File: U:\My Documents\Visual Studio 2008\WebSites\WebSite4\Def
==========================
Is there a string other than Date i should be using?
I can display the current date elsewhere on the page by using:
<%=DateString()%>
but i cant place it in the value="" tag because it simply renders as text and does not populate the date.
Thanks for your help,
Jason
golfDoctor,
will i still require the vb i was working on with ArachnidCreations? Also, do i need to wrap the if statement in anything? And lastly, the comment " // in the page load", does this imply that i need to create an Page Load Event? If so, where would I do that?
I am eager to test this and will do so around 7:30 AM EST in the morrow.
Jason
Or, if you need exact example. Today's date and your field:
'code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DateSubmitted.Text = Format(Now(), "MM/dd/yyyy")
End Sub
'page
<asp:TextBox ID="DateSubmitted" runat="server" CssClass="text"></asp:TextBo
Business Accounts
Answer for Membership
by: alainbrydenPosted on 2009-08-12 at 08:56:57ID: 25080009
This article should solve your problem: http://www.plus2net.com/as p-tutorial /date-toda y.php
--
Alain