Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Have a form in aspx using javascript to create a calendar for date selection.
How to I get the date into the aspx.cs? Using sql in the aspx.cs to get data based on the start and end date.
Posted

Using
C#
ICallbackEventHandler

front:
<script>CallServer(escape(Value you want to transfer))</script>
background:
C#
public partial class Work_RiZhi : System.Web.UI.Page, ICallbackEventHandler{
        string returnvalue;
 protected void Page_Load(object sender, System.EventArgs e)
    {
             string CallbackScript = @"
        function CallServer(arg) {
         " + ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", null) + @";
        }
        ";
        ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", CallbackScript, true);
    }
 public void RaiseCallbackEvent(string eventArgument)
    {
        if (eventArgument != string.Empty)
        {
getData(eventArgument);
}}
      public string GetCallbackResult()
    {
        return returnvalue;
    }
private string getData(string ID)
{
    retrun "new "+id;
}
 
Share this answer
 
v2
Comments
Member 14647686 10-Nov-19 5:10am    
sadads
Member 14647686 10-Nov-19 5:10am    
wrerwer
Hi,

As per my understanding you need to get the value of a date control which you have done using Javascript. On the post back you need to have this value in cs page and then get the value from SQL.

Solution

In this case please put a hidden field in the page.

ASP.NET
<asp:hiddenfield id="hdValue" runat="server" xmlns:asp="#unknown" />


Then assign the value to the hidden field on selection using Javascript.

HTML
document.getElementById('hdValue').value = '<< Selected value from calender>>';

On post back you can get the value from the hidden field.


In case if you looking for data to be refreshed without postback then need to go for Call Back or Ajax.

Hope this helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900