Keyboard Enter to select

5 posts, 1 answers
  1. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 10 Aug 2014 Link to this post

    Hello

    Im trying to fire a simple onclientnodeclicking event on my treeview via keyboard (hitting enter).

    But I find that upon pressing Enter on the node, besides firing the onclientnodeclicking event, also  fires a postback on a Button1 situated on the same page.
    How do I prevent this?

    Using the mouseClick on the treenode works as expected, without Button1 postback.

    Simple example to illustrate:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">

            function NodeClick(sender, eventArgs) {           
               var node = eventArgs.get_node();
               alert(node.get_text());
              // eventArgs.set_cancel(true);                    
            }    
            
        </script>


    </head>

    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>       
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"  TabIndex="1" />
       <br /><br />
        <telerik:RadTreeView ID="RadTreeView1" Runat="server" Width="200px" Height="200px"  TabIndex="2"
            onclientnodeclicking="NodeClick" ResolvedRenderMode="Classic">
            <Nodes>
                <telerik:RadTreeNode runat="server" PostBack="False" Text="Root RadTreeNode1">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode runat="server" PostBack="False" Text="Root RadTreeNode2">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode runat="server" PostBack="False" Text="Root RadTreeNode3">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeView> 
        
        </div>
        </form>
    </body>
    </html>

  2. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 10 Aug 2014 in reply to Mark Link to this post

    .. and here is the serverside Button1 action.

     protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write("Button postback:" + DateTime.Now.ToString());
           
        }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Aug 2014 in reply to Mark Link to this post

    Hi Mark,

    Try to set the UseSubmitBehavior property of Button to false which works fine at my end.

    ASPX:
    <asp:Button ID="Button1" runat="server" UseSubmitBehavior="false" Text="Button" OnClick="Button1_Click" TabIndex="1" />

    Thanks,
    Shinu.
  5. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 11 Aug 2014 in reply to Shinu Link to this post

    Thanks for your answer Shinu !

    Following your pointer I ended up replacing the imagebutton with an image (w. onclick event.)
    I works great. 

    However my main problem turns out to be that radTreeview handles nodeselection with Keyboard -"Enter", and MouseClick different.

    Mouseclick only fires the defined  rt clientevents , while "Enter" fires a fullblown postback regardless nodes have postback=false.
    How do I prevent Enter from postback'ing my nodes?

    Regards 
    Mark
  6. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 11 Aug 2014 in reply to Mark Link to this post

    ok I found a way out on this  one.

    Enter key in my Radtreeview will hit any submittable control on the page resulting in a postback.
    Regardless my Radtreeview only has clientevent attached.

    however; if I end my clientevent function with :
     $telerik.cancelRawEvent(eventArgs.get_domEvent()); 

    It will stop any further submitting.




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