This is a migrated thread and some comments may be shown as answers.

DatePicker Stop Postback onkeypress Enter

5 Answers 310 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Tom Lynch
Top achievements
Rank 1
Tom Lynch asked on 20 May 2011, 04:02 PM
Hello,

I'm having trouble stopping a form from doing a postback when the Enter key is pressed inside the DatePicker.  This should be pretty straight foward, I would think, but this code isn't working.

<

 

telerik:RadDatePicker ID="dtpDate" runat="server" onkeypress="dateStopEnter(this, event)"></telerik:RadDatePicker>

 

function dateStopEnter(sender, e) {
    e = e || window.event;
    if (e.keyCode == 13)
        return false;
}

The javascript event handler is called and it reaches the "return false" line, but it still allows a postback.  I'm using File Version 2009.3.1104.35 of Telerik.Web.UI.dll and the form is contained in a .ascx file that is part of a Dot Net Nuke module.  The module is installed in a DNN site...I don't know, maybe DNN is complicating this. 

Tom

 

 

 

 

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Gimmik
Top achievements
Rank 1
answered on 20 May 2011, 07:13 PM
Have you tried setting  AutoPostBack="false"  for your RadDatePicker?

-Gimmik
0
Tom Lynch
Top achievements
Rank 1
answered on 20 May 2011, 07:51 PM
Just tried it.  AutoPostBack doesn't seem to work.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 May 2011, 09:01 AM
Hello Tom,

Try the following approach.
aspx:
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" onkeydown="handleClickEvent(this,event)">  
</telerik:RadDatePicker>

Javascript:
function handleClickEvent(sender, args)
{
  args = args || window.event;
    if (args.keyCode == 13)
    {
        args.cancelBubble = true;
        args.returnValue = false;
        if (args.preventDefault) args.preventDefault();
        if (args.stopPropagation) args.stopPropagation();
    }
}

Thanks,
Shinu.
0
Tom Lynch
Top achievements
Rank 1
answered on 24 May 2011, 07:27 PM
Thanks!  That works.
0
Luis Miguel Ruidias Lara
Top achievements
Rank 1
answered on 06 Sep 2012, 03:57 PM
I´m using the same, but i need a function that verify if the date is OK, something like :

function handleClickEvent(sender, args) 
    {
        args = args || window.event;

        if (args.keyCode == 13)
        {
if(!args.dateIsOK())
{
            args.cancelBubble = true;
            args.returnValue = false;
            if (args.preventDefault) args.preventDefault();
            if (args.stopPropagation) args.stopPropagation();
}
        }
    }

the parameters args have a function like that? or any idea??

Thanks !!

Tags
Calendar
Asked by
Tom Lynch
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
Tom Lynch
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Luis Miguel Ruidias Lara
Top achievements
Rank 1
Share this question
or