Simple put current date in a txtbox in Formview - Gozirra

P

Phillip Vong

Using VS2005 w/ simple aspx in VB.net

I have a simple databound textbox "LastMtgText" in a formview in the Insert
template.

All I want to do is make the default date of today when someone goes to
Insert template so they do not have to put in todays date. Here is my code,
what am I doing wrong? I know how to do this when not using Formview.

'-----This puts in the current date

Dim dtmToday As Date

dtmToday = Now.Date


Dim convDate As String

convDate = CStr(dtmToday)


Dim LastMtgLabel As Label

LastMtgLabel = FormView1.FindControl("LastMtgTextBox")

LastMtgLabel.Text = dtmToday






Gozirra - I thought I understood what you were trying to teach me about
conversion so I thought this would be easy but I can not get this to work.
Can you please build a simple form and try this? This works fine when not
in Formview.
 
P

Phillip Vong

I got it. But I have one last problem.

Dim dtmToday As String
dtmToday = Now.Date.ToString("MM/d/yyy")

Dim LastMtgLabel As TextBox
LastMtgLabel = FormView1.FindControl("LastMtgTextBox")
LastMtgLabel.Text = dtmToday


This codes puts in today's date perfectly in my Textbox, but if I try to
change the date to something else like 12/15/1945 and Insert it, it posted
today's date. No matter what I change it to, it will post today's date. Is
there a reason for this? This code was in the PageLoad so why would it do
this?
 
M

MrGreen

I had the same problem, thanks for your help.
This one works for me (put in the if Not IsPostBack..... End if).
I can change the date now en it submits correctly to the database.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim dtmToday As String
If Not IsPostBack Then
dtmToday = Now.Date.ToString("dd/MM/yy")
Dim LastMtgLabel As TextBox
LastMtgLabel = FormView1.FindControl("datumTextBox")
LastMtgLabel.Text = dtmToday
End If
End Sub
 
P

Phillip Vong

That's perfect!

Thanks!

MrGreen said:
I had the same problem, thanks for your help.
This one works for me (put in the if Not IsPostBack..... End if).
I can change the date now en it submits correctly to the database.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim dtmToday As String
If Not IsPostBack Then
dtmToday = Now.Date.ToString("dd/MM/yy")
Dim LastMtgLabel As TextBox
LastMtgLabel = FormView1.FindControl("datumTextBox")
LastMtgLabel.Text = dtmToday
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top