Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:02:54+00:00 2026-05-26T15:02:54+00:00

I am working with the C#, ASP.NET framework [very new to this environment]. This

  • 0

I am working with the C#, ASP.NET framework [very new to this environment]. This is what I want to achieve:

  • Pass data from jQuery Datepicker textbox to controller
  • Parse the date, database query from the selected range
  • Asynchronously, send queried rows back to page to update content

Here is the HTML:

<form id="date" runat="server">
    <asp:Label AssociatedControlId="from_date" Text="From:" runat="server" />
    <asp:TextBox ID="from_date" Text="" runat="server" />
    <asp:Label AssociatedControlId="to_date" Text="To:" runat="server" />
    <asp:TextBox ID="to_date" Text="" runat="server" />
</form>

I have this snippet on the client side to handle the change event:

var dates = $('#from_date, #to_date').datepicker({
                if ( this.id == "to_date" )
                    $('#to_date').change();
            });

To call in the controller:

protected void to_date_UpdateHandler( object sender, EventArgs e ) {
  /* from here, I would query within the ranges in the "from_date" 
     and "to_date" textboxes */
}

Obviously, this will cause a page refresh, but I want to pass the data along asynchronously. How should I go about achieving this? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:02:55+00:00Added an answer on May 26, 2026 at 3:02 pm

    It’s a little unclear from your question which particular jQuery ‘datepicker’ plugin you are using, so I will proceed to use the jQuery UI date picker for this example.

    First off, there are some things you should be aware of when working with jQuery and ASP.NET WebFroms. Specifically, up until very recently, when server controls are rendered, their IDs get mangled by .NET. It is usually a good idea to stick to CSS classes when doing lots of client side scripting, but if you must use IDs, you can select controls like so:

    var $toDate = $('input[id$=to_date]');
    

    Secondly, you will need to communicate with the server via WebMethods or by configuring an ASPX page to return XML or JSON. ASP.NET MVC really makes this easy, but it’s possible in WebForms and definitely worth your time (I despise UpdatePanels).

    Now to some code.

    ASPX:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Example ASP.NET/jQuery Datepicker</title>
        <link type="text/css" rel="stylesheet" href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/themes/redmond/jquery-ui.css" />
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js"></script>
        <script type="text/javascript" src=" http://jquery-json.googlecode.com/files/jquery.json-2.3.min.js"></script>
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.js"></script>
    
        <script type="text/javascript">
    
            // On DOM ready...
            $(function() {
    
                // Cache the date pickers
                var $fromPicker = $('.from_date'),
                    $toPicker = $('.to_date');
    
                // Init the date pickers
                $fromPicker.datepicker();
                $toPicker.datepicker();
    
                // Handle change event for 'to' date
                $toPicker.change(function(e) {
    
                    // Get the dates
                    var fromDate = $fromPicker.datepicker('getDate');
                    var toDate = $(this).datepicker('getDate')
    
                    // prepare the data to be passed via JSON
                    var dates = {
                        fromDate: fromDate,
                        toDate: toDate
                    };
    
                    // Call the web method
                    $.ajax({
                        type: 'POST',
                        url: 'Default.aspx/GetDate',
                        data: $.toJSON(dates),
                        contentType: 'application/json; charset=utf-8',
                        dataType: 'json',
                        success: function(msg) {
                            alert(msg.d);
                        }
                    });
    
                });
    
                // Log errors
                $(".log").ajaxError(function() {
                    $(this).text("Error in ajax call.");
                });
    
            });
    
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager" EnablePageMethods="true" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="from_date_lbl" AssociatedControlID="from_date" Text="From:" runat="server" />
        <asp:TextBox ID="from_date" CssClass="from_date" Text="" runat="server" />
        <asp:Label ID="to_date_lbl" AssociatedControlID="to_date" Text="To:" runat="server" />
        <asp:TextBox ID="to_date" CssClass="to_date" Text="" runat="server" />
        <asp:Label ID="log_lbl" CssClass="log" runat="server" />
        </form>
    </body>
    </html>
    

    ASPX.CS

    using System;
    using System.Web.Services;
    
    public partial class _Default : System.Web.UI.Page
    {
        [WebMethod]
        public static string GetDate(string fromDate, string toDate)
        {
            DateTime dtFromDate;
            DateTime dtToDate;
    
            // Try to parse the dates
            if (DateTime.TryParse(fromDate, out dtFromDate) &&
                DateTime.TryParse(toDate, out dtToDate))
            {
                // Perform calculation and/or database query
    
                return "success!";
            }
    
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in asp.net .net framework 4, i have a data grid and
I'm working with ASP.NET MVC but this really applies to any MVC framework. I
I am working in ASP.net with .Net Framework 2.0 and VS 2008 Team System
I am working through Steve Sanderson's book Pro ASP.NET MVC Framework and I having
I'm working on an ASP.net 3.5 website with MooTools as the AJAX framework. I
I am currently working on an web application that uses ASP.NET 2.0 framework. I
I am working with master page in ASP.NET (3.5) MVC Framework (1.0). I am
I've been working through the book Pro ASP.NET MVC 2 Framework by Steven Sanderson.
I'm working through installing the N2 content management framework in an ASP.NET website project.
I'm working with the ASP.Net MVC 3 framework and I'm integrating dependency injection into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.