DatePicker Stop Postback onkeypress Enter

6 posts, 1 answers
  1. Tom Lynch
    Tom Lynch avatar
    78 posts
    Member since:
    Mar 2005

    Posted 20 May 2011 Link to this post

    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

     

     

     

     

     

     

     

     

  2. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 20 May 2011 Link to this post

    Have you tried setting  AutoPostBack="false"  for your RadDatePicker?

    -Gimmik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tom Lynch
    Tom Lynch avatar
    78 posts
    Member since:
    Mar 2005

    Posted 20 May 2011 Link to this post

    Just tried it.  AutoPostBack doesn't seem to work.
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 May 2011 Link to this post

    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.
  6. Tom Lynch
    Tom Lynch avatar
    78 posts
    Member since:
    Mar 2005

    Posted 24 May 2011 Link to this post

    Thanks!  That works.
  7. Luis Miguel Ruidias Lara
    Luis Miguel Ruidias Lara avatar
    1 posts
    Member since:
    Jan 2010

    Posted 06 Sep 2012 Link to this post

    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 !!

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017