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

Keyboard Enter to select

4 Answers 16 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Aug 2014, 07:06 PM
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>

4 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 10 Aug 2014, 07:07 PM
.. and here is the serverside Button1 action.

 protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("Button postback:" + DateTime.Now.ToString());
       
    }
0
Accepted
Shinu
Top achievements
Rank 1
answered on 11 Aug 2014, 05:41 AM
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.
0
Mark
Top achievements
Rank 1
answered on 11 Aug 2014, 07:25 AM
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
0
Mark
Top achievements
Rank 1
answered on 11 Aug 2014, 06:28 PM
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.




Tags
TreeView
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or