PDA

View Full Version : [CLOSED] Datepicker help



Jurke
Sep 11, 2008, 11:53 AM
Hi
I just started looking at the DatePicker, and there are some things that I cant get to work.
*First I do not want the user to be able to choose dates before todays date. I use MinDate for that, and that does not work. Maybe im using the wrong property.
*Second I want to be able to get the selected date in a buttonclick that is in an ajax event, and that does not work, I see no property in the datepicker that is loaded with the selected date.

Hope you can help me with this.






<ext:DatePicker ID="dpDate" runat="server" />




<ext:Button ID="btnSearch" runat="server" Text="Search" Icon="ArrowRefresh" >
<AjaxEvents> <Click OnEvent="btnSearch_Click"></Click></AjaxEvents>
</ext:Button>






protected override void OnInit(EventArgs e){
base.OnInit(e);
DateTime dtDagensdatum = new DateTime();
dpDate.MinDate = dtDagensdatum;
}


protected void btnSearch_Click(object sender, AjaxEventArgs e){


pnlSearchResult.Html = dpDate.SelectedDate;








}

Best regards
Mikael Jürke

geoffrey.mcgill
Sep 11, 2008, 1:07 PM
Hi Mikael,

I've confirmed the bugs. I recently changed how the DateTime objects were getting serialized into Json, and that change appears to have affected the MinDate property.

The second issue with the SelectedDate not posting back to the server during an AjaxEvent was fixed yesterday. The following forum post outlines the ajaxevent issue, see http://forums.ext.net/showthread.php?postid=1647.aspx.

I'll update this thread as soon as the MinDate bug has been fixed.

Jurke
Sep 12, 2008, 5:12 AM
Okay great, thank you!

geoffrey.mcgill
Sep 12, 2008, 6:38 PM
The MinDate bug has been fixed and committed to svn.

Thanks for pointing out the problem originally. 

geoffrey.mcgill
Sep 15, 2008, 8:32 AM
Hi Jurke,

I think what you want to be doing is setting the .MinDate property to "DateTime.Today" and not "new DateTime()". The default DateTime constructor returns DateTime.MinValue and not "today", which I have to say is rather unintuitive.

Example


// Old
dpDate.MinDate = new DateTime();

// New
dpDate.MinDate = DateTime.Today;
Hope this helps solve the problem.

Jurke
Sep 15, 2008, 8:45 AM
Yes that helped, on the MinDate issue. Thanks!

But I still get an error when trying to get the SelectedDate property in an AjaxEvent onclick event. It says "Run time error in Microsoft JScript: 'nul' is null or is not an objct". This was a translation from the swedish error message. and points to the code in coolite.axd




this.value=B.clearTime(true


Best regards
Mikael

geoffrey.mcgill
Sep 15, 2008, 9:10 AM
I'm not sure what's happening in your sample. Can you post a simplified code sample demonstrating how to reproduce the error?

I made the following sample and it appears to work as expected.

Example


<%@ Page Language="C#" %>

<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.DatePicker1.MinDate = DateTime.Today;
}

protected void Button1_Click(object sender, AjaxEventArgs e)
{
this.Panel1.Html = this.DatePicker1.SelectedDate.ToString();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />

<ext:DatePicker ID="DatePicker1" runat="server" />

<ext:Button ID="Button1" runat="server" Text="Submit">
<AjaxEvents>
<Click OnEvent="Button1_Click" />
</AjaxEvents>
</ext:Button>

<ext:Panel ID="Panel1" runat="server" Height="300" Width="300" Title="Title" />
</form>
</body>
</html>

Does your Page compile? I ask because in the code sample you posted you are setting the .Html property (string) of a Panel with the .SelectedDate property (DateTime) of the DatePicker. I would expect that code to throw an Exception even before the initial Page_Load.

You should set the .Html property with a string.

Example


pnlSearchResult.Html = dpDate.SelectedDate.ToString();
Hope this helps.

Jurke
Sep 15, 2008, 11:49 AM
Hi
Thank you for your response! you are right, your example works great. It took me a while to figure out why my code did not work. The error occur when I add MS script manager. Se my exaple. It is exactly like yours but with the ms script manager.







<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test_Default" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1 transitional.dtd">


<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.DatePicker1.MinDate = DateTime.Today;
}


protected void Button1_Click(object sender, AjaxEventArgs e)
{
this.Panel1.Html = this.DatePicker1.SelectedDate.ToString();
}


</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<ext:DatePicker ID="DatePicker1" runat="server" />
<ext:Button ID="Button1" runat="server" Text="Submit">
<AjaxEvents>
<Click OnEvent="Button1_Click" />
</AjaxEvents>
</ext:Button>
<ext:Panel ID="Panel1" runat="server" Height="300" Width="300" Title="Title" />
</form>
</body>
</html>







Best regards
Mikael Jürke

Jurke
Sep 16, 2008, 7:42 AM
Hi
Geoffrey, can you please get back to me about this bug?
I really need to know if you are able to fix this.

Best regards
Mikael

geoffrey.mcgill
Sep 16, 2008, 9:22 AM
Hi Mikael,

I'm working on a fix right now. This is a bug (defect) in both ExtJS and MicrosoftAJAX. Unfortunately the two wrongs don't cancel each other out. Hopefully a fix will be available shortly.

Jurke
Sep 16, 2008, 9:32 AM
Hi!
Oh okay I see. Hope you can solve it. That would be great! Keep me posted!

Best regards
Mikael

geoffrey.mcgill
Sep 22, 2008, 5:26 AM
Hi Mikael,

The <ext:DatePicker> JavaScript error that was thrown when an <asp:ScriptManager> was also placed on the Page has been fixed.

The code has been committed to svn and will be publicly available with the v0.6 release.

Hope this helps.

geoffrey.mcgill
Sep 22, 2008, 6:34 AM
I found and fixed another error with how the <ext:DatePicker> .MinDate property was being set during the response from an AjaxEvent. If you svn updated since my post a few minutes ago, please update again.

Jurke
Sep 22, 2008, 6:52 AM
Great work.
Thank you!

Best regards
Mikael Jürke