17
Answers

How select Default today date in textbox control?

Narayana

Narayana

8y
428
1
Source code : 
<asp:TextBox ID="txtfrmDate" runat="server" Height="34px" type="date"
class="form-control" ></asp:TextBox>
 
C# code :
 
   txtfrmDate.text=convert.todatetime(DateTime.Now.ToString()).ToString("mm/dd/yyyy");
  or
 txtfrmDate.text=DateTime.Now.ToString("mm/dd/yyyy");
 
 
If i am running the website .It's not taking defaultly today date. 
 
 
Answers (17)
2
Mani Kandan

Mani Kandan

NA 2.6k 135.6k 8y
Hi,
 
try this
  1. this.txtDate.text = DateTime.Today.ToString("dd/MM/yyyy");  
2
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 8y
@Narayana
 
The format you applied is not appropriate, format should be like this
  1. txtfrmDate.text=DateTime.Now.ToString("MM/dd/yyyy");  
For more information about format, please visit
 https://www.dotnetperls.com/datetime-format
1
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 8y
I think the issue is with browser compatibility, run your application in Internet Explorer (you will get the desired result).
 
For more info, refer this link
http://www.c-sharpcorner.com/UploadFile/4b0136/introducing-html-5-date-input-type-in-Asp-Net/
1
Samatha Reddy

Samatha Reddy

NA 127 7 8y
Hi...
Please try once this code
 
if(!IsPostBack)
{
txtfrmDate.Text = DateTime.Now.Date.ToString("MM/dd/yyy");
1
Rafnas T P

Rafnas T P

NA 12.2k 435.7k 8y
try this below
in page load
inside
if (!Page.IsPostBack)

{

txtfrmDate.Text = DateTime.Now.ToString("mm/dd/yyyy");
 
}
 
 
1
Ramesh Palanivel

Ramesh Palanivel

NA 9.5k 138.6k 8y
Hi Narayana,
 
Try this code,
 
TextBox1.Text = DateTime.Now.ToShortDateString(); 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Amit,
 
Thank for your reply.
 
But my application not compatibility to Internet explorer. only in chrome compatibility.
help me for this issue. 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Amit,
 
  Debugging through break point .it's getting in text as 15-03-2017. but not dispalyed in output. i.e main problem. I can try so many times it's not working.
 
if plain textBox control then it dispaly but type="Date" in asp control it not dispaly . 
0
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 8y
@Narayana
 
Points to be consider in this case:
1. Put a breakpoint in the textbox and see what value is coming, is it the desired format?
2. Cross check that the value of textbox is not being changed on other part of code.
 
 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Rafnas,
 
It's also not working. 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Amit ,
 
It's not working. my pc date format like  dd-mm-yyyy .
0
Rafnas T P

Rafnas T P

NA 12.2k 435.7k 8y
try this
 
txtfrmDate.Date=DateTime.Now.ToString("mm/dd/yyyy");
0
Amit Gupta

Amit Gupta

NA 16.5k 25.7k 8y
What happened? Isn't working?
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Amit, 
 
 please check once. 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Vignesh,
 
Thanks for giving reply. I am asking date not for time.If i am giving plain textbox then it's ok.
but I am giving date format. 
0
Narayana

Narayana

NA 93 1.7k 8y
Hi Ramesh,
 
   I have already try that code.It's not display. 
0
Vignesh Mani

Vignesh Mani

NA 13.4k 938.4k 8y
https://www.daniweb.com/programming/software-development/threads/133436/set-current-time-in-textbox