python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Date Calendar

Date Calendar in ASP.NET TextBox with image icon

Hello everyone, 


In this post, i'm going to share the code-sample for
 date calendar date-time calendertextbox in asp.net with c#


This example is simple and easily understandable code using asp.net with c# 

Table of Contents 


1. In the 1st step, code-sample for C# (.cs page)
2. In the 2nd step, code-sample for aspx page
In the 1st step, we write the code for the cs file in asp.net page i.e. .aspx.cs

namespace myWebApplication
{
    public partial class _Default : BaseFeature
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CalOne.Visible = false;
            CalTwo.Visible = false;
        }

        protected void imgButtonOne_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (txtDate.Text.Trim() != "")
                    CalOne.SelectedDate = Convert.ToDateTime(txtDate.Text);
            }
            catch (Exception e)
            {
                throw e;
            }
            CalOne.Visible = true;
        }

        protected void CalOne_SelectionChanged(object sender, EventArgs e)
        {
            txtDate.Text = CalOne.SelectedDate.ToShortDateString();
            CalOne.Visible = false;
        }

        protected void imgButtonTwo_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (txtFronDate.Text.Trim() != "")
                    CalTwo.SelectedDate = Convert.ToDateTime(txtFronDate.Text);
            }
            catch(Exception e)
            {
                throw e;
            }
            CalTwo.Visible = true;
        }

        protected void CalTwo_SelectionChanged(object sender, EventArgs e)
        {
            txtFronDate.Text = CalTwo.SelectedDate.ToShortDateString();
            CalTwo.Visible = false;
        }

    }

}


In the 2nd step, we write the code for the view in asp.net page i.e. .aspx page

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">

    <asp:TextBox ID="txtDate" runat="server" Width="70"></asp:TextBox>
    <asp:ImageButton ID="imgButtonOne" runat="server" CausesValidation="false"Height="19px" Width="15px" ImageUrl="images/cal.gif" OnClick="imgButtonOne_Click" />

    <asp:TextBox ID="txtDateFrom" runat="server" Width="70"></asp:TextBox>
    <asp:ImageButton ID="imgButtonTwo" runat="server" ImageUrl="images/cal.gif"OnClick="imgButtonTwo_Click" />

    <asp:Calendar ID="CalOne" runat="server"OnSelectionChanged="CalOne_SelectionChanged">
    </asp:Calendar>

    <asp:Calendar ID="CalTwo" runat="server"OnSelectionChanged="CalTwo_SelectionChanged">
    </asp:Calendar>

</asp:Content>


Notes

download and add to this image in "images" folder in our  application for display to calender textbox 
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions