locked
DatePicker Control RRS feed

  • Question

  • User-797751191 posted

    Hi

      Is there any datapicker control in c# . I am using Studi 2012

    Thanks

    Monday, July 15, 2019 4:51 PM

Answers

  • User475983607 posted

    Hi

      Is there any datapicker control in c# . I am using Studi 2012

    Thanks

    A date picker is a client side construct.  HTML 5 complaint browsers have this feature and there are JavaScript libraries as well.

    C# runs on the server not the client.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 5:47 PM
  • User839733648 posted

    Hi jsshivalik,

    You could use Calender, TextBox and Button control to achieve the datepicker effect.

    First, set the calender to invisible.

    Then in the button click event to make the calender visible.

    And in the calender's SelectionChanged event to get the selected date.

    Here is a simple demo and hope this will be helpfu to you.

    .aspx

        <form id="form1" runat="server">
            <div>
                <asp:Calendar ID="Calendar1" runat="server" Visible="false" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
            </div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="GetDate" OnClick="Button1_Click"/>
    
        </form>

    code-behind.

            protected void Button1_Click(object sender, EventArgs e)
            {
                Calendar1.Visible = true;
            }
    
            protected void Calendar1_SelectionChanged(object sender, EventArgs e)
            {
                TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
                Calendar1.Visible = false;
            }
    

    result:

    For more, you could refer to: https://www.c-sharpcorner.com/article/create-datetimepicker-control-in-asp-net/

    You could also use AJAX Control Toolkit Calendar Extender, here is a refernece that describe step by step:

    https://www.c-sharpcorner.com/UploadFile/2f59d0/use-ajaxcontroltoolkit-calendar-extender-with-Asp-Net/

    Besides, as mgebhard has mentioned, javascript libraries of datepicker is more encouraged to use.

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 2:26 AM

All replies

  • User475983607 posted

    Hi

      Is there any datapicker control in c# . I am using Studi 2012

    Thanks

    A date picker is a client side construct.  HTML 5 complaint browsers have this feature and there are JavaScript libraries as well.

    C# runs on the server not the client.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 5:47 PM
  • User839733648 posted

    Hi jsshivalik,

    You could use Calender, TextBox and Button control to achieve the datepicker effect.

    First, set the calender to invisible.

    Then in the button click event to make the calender visible.

    And in the calender's SelectionChanged event to get the selected date.

    Here is a simple demo and hope this will be helpfu to you.

    .aspx

        <form id="form1" runat="server">
            <div>
                <asp:Calendar ID="Calendar1" runat="server" Visible="false" OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
            </div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="GetDate" OnClick="Button1_Click"/>
    
        </form>

    code-behind.

            protected void Button1_Click(object sender, EventArgs e)
            {
                Calendar1.Visible = true;
            }
    
            protected void Calendar1_SelectionChanged(object sender, EventArgs e)
            {
                TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
                Calendar1.Visible = false;
            }
    

    result:

    For more, you could refer to: https://www.c-sharpcorner.com/article/create-datetimepicker-control-in-asp-net/

    You could also use AJAX Control Toolkit Calendar Extender, here is a refernece that describe step by step:

    https://www.c-sharpcorner.com/UploadFile/2f59d0/use-ajaxcontroltoolkit-calendar-extender-with-Asp-Net/

    Besides, as mgebhard has mentioned, javascript libraries of datepicker is more encouraged to use.

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 2:26 AM