How to display current date by default in textbox

Posted by Amar888 under Regular Expressions on 3/26/2010 | Views : 59146 | Status : [Member] | Replies : 3
hi,
How to display current date by default in textbox when page loads i mean if user enters the data by default date should be there
if user wants to change just click on date picker.

If u people know about this tell me .




Responses

Posted by: Bunty_18 on: 3/26/2010 [Member] Starter

Up
0
Down
On the Page Load event,write the below code

if(!isPostBack)
textbox1.Text = DateTime.Today.ToShortDateString();



Amar888, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/26/2010 [Member] Bronze

Up
0
Down
//code behind:

protected void Page_Load(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
TextBox tb = DetailsView1.FindControl("DateTextBox") as TextBox;
tb.Text = DateTime.Now.ToString("d");
}
}

//aspx:
<form id="form1" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateRows="False" DataKeyNames="ID"
DataSourceID="LinqDataSource1">
<Fields>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<ItemTemplate>
<%# Eval("Date") %>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="DateTextBox" runat="server"></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
//...


Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Amar888, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/21/2010 [Member] Bronze

Up
0
Down
txtdate.Text = DateTime.Now.ToString("dd/MM/yyyy");

Thanks
Pavan Kumar
Mark Answer if this fits the need

Amar888, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response