locked
how to get previous and next dates in textbox RRS feed

  • Question

  • User-1363380821 posted

    Hi,

    i have one textbox and two buttons.

    button1 name as prev,button2 name as next.The textbox contain current date.

    If iam clicking next button textbox will show the next date.

    if iam clicking prev button textbox will show the previous date.

    please help me...

     

    Wednesday, May 25, 2011 6:42 AM

Answers

  • User-1828494216 posted

    Hi,

     

    <body>
        <form id="form1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="prev" onclick="Button1_Click" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" Text="next" onclick="Button2_Click" />
        </form>
    </body>
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            TextBox1.Text = DateTime.Now.ToShortDateString();
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Parse(TextBox1.Text);
        TextBox1.Text = dt.AddDays(-1).ToShortDateString();
    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Parse(TextBox1.Text);
        TextBox1.Text = dt.AddDays(1).ToShortDateString();
    }
    

     

     Convert C# to VB.NET

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 25, 2011 8:14 AM