When right clicking an item in a treeview and clicking something in the context menu, the ContextMenuItemClick event handler is getting fired twice which is inevitably causing issues with some of the code in the handler. I really can't see how anything else in my code can make that happen, any ideas?
4 Answers, 1 is accepted
0
Paul Wood
Top achievements
Rank 1
answered on 04 May 2008, 12:09 PM
When debugging the application, I notice that having a look at sender shows me that the treeview has two datasourceID properties (both the same being my sqldatasource) which I find highly unusual and might be the cause of this problem. Is this a bug in VWD or RadTreeView?
Here is a simple stripped down version with the tvwSite_ContextMenuItemClick handler just having a simple Response.Write in it showing the double fire.
Here is a simple stripped down version with the tvwSite_ContextMenuItemClick handler just having a simple Response.Write in it showing the double fire.
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <html> |
| <head> |
| <title>TreeView Test</title> |
| </head> |
| <body> |
| <form id="frmTreeView" runat="server"> |
| <asp:ScriptManager ID="scmTreeView" runat="server" /> |
| <asp:SqlDataSource ID="sqlSitePages" runat="server" ConnectionString="<%$ ConnectionStrings:iPadmin %>" |
| SelectCommand="usp_iP_SitePages" SelectCommandType="StoredProcedure"> |
| <SelectParameters> |
| <asp:Parameter Name="Site" DefaultValue="1" Type="Int32" /> |
| <asp:ProfileParameter Name="License" PropertyName="License" Type="Int16" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <telerik:radtreeview id="tvwSite" runat="server" skin="Office2007" |
| datasourceid="sqlSitePages" oncontextmenuitemclick="tvwSite_ContextMenuItemClick" |
| datafieldid="iP_PageListingID" datafieldparentid="Parent_PageListingID" datavaluefield="iP_PageListingID" |
| datatextfield="Title"> |
| <ContextMenus> |
| <telerik:RadTreeViewContextMenu runat="server" ID="cxmPage" Skin="Outlook"> |
| <Items> |
| <telerik:RadMenuItem Text="Properties" Value="Properties" /> |
| </Items> |
| </telerik:RadTreeViewContextMenu> |
| </ContextMenus> |
| </telerik:radtreeview> |
| </form> |
| </body> |
| </html> |
0
Accepted
Hi Paul Wood,
Is it possible that you declared the ContextManuItemClick event handler using the Handles statement. Thus, the event will be fired twice as the event is first defined in the aspx file and secondly it is attached via the Handles statement. Therefore, you should delete the Handles statement from the ContextMenuItm declaration in the codebehind.
Hope this helps.
Kind regards,
Nick
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Is it possible that you declared the ContextManuItemClick event handler using the Handles statement. Thus, the event will be fired twice as the event is first defined in the aspx file and secondly it is attached via the Handles statement. Therefore, you should delete the Handles statement from the ContextMenuItm declaration in the codebehind.
Hope this helps.
Kind regards,
Nick
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Paul Wood
Top achievements
Rank 1
answered on 07 May 2008, 02:54 AM
Thank you, this solved the problem. However, I'm unsure about why it is not required when creating the event handler (when AutoEventWireup is set to false). Is it just something to do with the RAD controls as opposed to normal ASP.NET controls?
0
Hi Paul Wood,
Actually, this is more like a general ASP.NET behavior. If you hooked on the event in the codebehind without setting the inline property, your approach should have been working as expected.
Regards,
Nick
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Actually, this is more like a general ASP.NET behavior. If you hooked on the event in the codebehind without setting the inline property, your approach should have been working as expected.
Regards,
Nick
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
