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

Inputbox always with a date on open

Hello,
I have created a input box with the following code.
But every time it's open I want it to display a date 7 days ahead of todays date.
New to .asp but wanted to try something like "today()+7" but wasn't working

Can anyone help?
Thanks
<asp:TextBox ID="TextBox1" runat="server"  Width="120px"></asp:TextBox>

Open in new window

0
ShockUK
Asked:
ShockUK
  • 6
  • 5
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
try this

<asp:TextBox ID="TextBox1" runat="server"  Width="120px"
             text='<%# Now().AddDays(7).tostring() %>'
></asp:TextBox>
 

Open in new window

0
 
ShockUKAuthor Commented:
When I input the above I get the following error

Error          The name 'Now' does not exist in the current context      C:\test\AccNum.aspx      
0
 
David RobitailleAnalyst ProgrammerCommented:
and this?
<asp:TextBox ID="TextBox1" runat="server"  Width="120px"
             text='<%# System.DateTime.Now().AddDays(7).tostring() %>'
></asp:TextBox>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
David RobitailleAnalyst ProgrammerCommented:
did that answer your question?
0
 
ShockUKAuthor Commented:
Now I get this error message

Error      Non-invocable member 'System.DateTime.Now' cannot be used like a method.      
0
 
David RobitailleAnalyst ProgrammerCommented:
well, I really sorry it`s my fault
remove the () after the "Now"
System.DateTime.Now.AddDays(7).tostring()
that time, it Will work
http://bytes.com/forum/thread582980.html 

<asp:TextBox ID="TextBox1" runat="server"  Width="120px"
             text='<%# System.DateTime.Now.AddDays(7).tostring() %>'
></asp:TextBox>

Open in new window

0
 
ShockUKAuthor Commented:
lol
Now it doesn't look like the .tostring() part
Is there anything I need to do in the scripting page aswell to get this working or just the .aspx page?
0
 
ShockUKAuthor Commented:
Got past it with the below but now the box is just blank...
<asp:TextBox ID="TextBox1" runat="server"  Width="120px"
             text='<%# System.DateTime.Now.ToShortTimeString() %>'
></asp:TextBox>

Open in new window

0
 
David RobitailleAnalyst ProgrammerCommented:
ok, ok , ok
replace your textbox with this:

<asp:TextBox ID="TextBox1" runat="server" Width="120px" />
and put this ind code bhind.
This time, I tested it, i know should did id before, my appologies.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
If Not Page.IsPostBack Then 
TextBox1.Text = System.DateTime.Now.AddDays(7).ToShortDateString() 
End If 
End Sub
 
 

Open in new window

0
 
ShockUKAuthor Commented:
Thanks mate,
Wish I could give you more than 500 points for this one
Bet it was one of those thread you wish you never picked up
0
 
David RobitailleAnalyst ProgrammerCommented:
I m gald i could help! If it was a long thread , it was only because I dident tested it. It was a really simple problem to me and that fact it was so simple make me cut the corner round and dont test it. 500 points is more than enough for that kind of question.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now