CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 6/26/2007 3:25:02 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 7 Views: 42 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
8 Items, 1 Pages 1 |< << Go >> >|
whatispunk
Asp.Net User
Menu control with SiteMapDataSource not firing MenuItemClick6/26/2007 3:25:02 PM

0/0

I have a menu control and I am using the Sitemap as a datasource to generate the menu contents.

Has anyone ever done this and noticed the MenuItemClick event doesn't fire?

How can I catch a click event on one of the <a> elements in the menu items? 


Simple minds think alike. Great minds come up with something different.
eyad.salamin
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick6/26/2007 5:07:26 PM

0/0

 Hi there,

I guess you're using SiteMapDataSource as a datasource to your menu.

SiteMapDataSource sets the databindings of the menu by default as follows:

1. the TextFiled is bound by default to the Title attribute which is coming from the Web.sitemap file

2. the NavigationUrl is bound to the url attribute coming from Web.sitemap as well.

 if the menu nodes were bound to a specific field (or property) in the data source, then the menu items will be rendered as html links (<a href='the url coming from the web.sitemap'>Title</a>)

links are handled by the browser and doesn't post the page back to the server, rather browsers make a get request to the specified link. in this case you will never get to your MenuItemClick event handler.

However, in case the menu's "Navigation Url Field"  was not bound to any property, then the menu items will be rendered in very similar way a "Link Button" does, and will post back to the same page and reach your event handler.

try adding the following code inside the <asp:Menu> tags:

           <DataBindings>
                <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
            </DataBindings>

 and in your MenuItemClick event handler add the following code:

Response.Write("You clicked on " + e.Item.Text);

  and you'll see how it works perfectly!

Cheers,

Eyad. 


<%= Eyad.Salamin %>

<aspForums:DontForget>Don't forget to click on Mark as answer on the post that helped you.

This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. </aspForums:DontForget>
whatispunk
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick6/26/2007 5:28:01 PM

0/0

You are a king among men! Thanks so much!

I am indeed using a SiteMapDataSource as the DataSource for the menu control and thus the NavigationURL was being bound to the url attribute in the Web.sitemap and rendering as plain old html <a> tags. This was sort of my suspicion that there was no postback being made and I thought I might have to write some javascript. But adding the <DataBindings> code in there fixed it all. Now my MenuItemClick event is firing and I can finally wire this darn thing up to my AJAX update panels.

 

Saweeeet!! 

 


Simple minds think alike. Great minds come up with something different.
whatispunk
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick6/26/2007 6:24:22 PM

0/0

 

Well this isn't over afterall.

Now the event is firing but my menu doesn't do anything. It just posts back to the same page.

When you bind your menu to a SiteMapDataSource the DataBindings don't seem to matter. My code looks like this now:

 

                                <asp:Menu ID="Menu1" runat="server" CssSelectorClass="PageMenu" DataSourceID="SiteMapDataSource1"
                                    Orientation="Horizontal">
                                    <DataBindings>
                                        <asp:MenuItemBinding DataMember="siteMapNode" TextField="title" NavigateUrlField="url"/>
                                    </DataBindings>
                                </asp:Menu>
 

You'll notice I added the NavigateUrlField="url" into the MenuItemBinding but that doesn't do anything.

So I'm stuck once again.
 


Simple minds think alike. Great minds come up with something different.
whatispunk
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick6/26/2007 6:29:39 PM

0/0

Nevermind. It does work, it was the AJAX update panels that weren't changing. So now the event fires, but the AJAX update panels don't do what I thought they were going to do. 


Simple minds think alike. Great minds come up with something different.
p19101
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick7/7/2007 10:56:53 PM

0/0

 I had the same problem, removing NavigateUrlField makes my OnMenuItemClick work as it should, but how is my menu going to change page without it?

raytork
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick7/20/2007 12:04:37 PM

0/0

I have been following these threads and have used the information to change to a database backed menu which posts. I am putting the URL into value as suggested and redirecting in the menuitem_clicked event with:

string item = e.Item.Value;

Response.Redirect(item);

I find that this works fine for the items under my first menu item, but not those under the second. The menu items for the first post and I see my debug stop on the redirect line works. For the items under menu item 2, the post works ( I can debug through the javascript and see it), but the menuitem_click never fires. The next stop I get is in the page_load event. This seems very strange since in viewing the source, there is nothing unusual about the second menu item sub-items.

I would appreciate any ideas; thanks,

-- Ray

whatispunk
Asp.Net User
Re: Menu control with SiteMapDataSource not firing MenuItemClick7/20/2007 3:55:34 PM

0/0

Quite honestly, I got fed up with this and ditched the menu control entirely. Instead I crafted an AJAX Accordion into a menu control. It's much slicker and although I haven't tried yet, I am sure it should handle the asynchronous postbacks that I want to do. Also, I am going to use an IFrame in my content page to handle the redirects so that the rest of the page doesn't load. But these are just theories/ideas right now. I don't know if they will work. I haven't had much time to spend on this.

In your case, I don't know why your second level menu items wouldn't cause a Click event. Just make triple sure that you aren't setting the PostbackURL to anything.
 


Simple minds think alike. Great minds come up with something different.
8 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

Menu control with SiteMapDataSource not firing MenuItemClick ... Menu control with SiteMapDataSource not firing MenuItemClick, > ROOT > NEWSGROUP > ... Re: Menu control with SiteMapDataSource not firing MenuItemClick. 6/26 ...
Menu control with SiteMapDataSource not firing MenuItemClick ... Menu control with SiteMapDataSource not firing MenuItemClick, > ROOT > NEWSGROUP > ... Re: Menu control with SiteMapDataSource not firing MenuItemClick. 6/26 ...
menuItemClick event does not fire for second time - ASP.NET Forums ... Navigation Controls " menuItemClick event does not fire for ... I have added menu at design time in control ( not use databinding as sitemapdatasource) ...
When MenuItem.NavigateUrl is not set the MenuItemClick event isn't ... When MenuItem.NavigateUrl is not set the MenuItemClick event isn't fired! ... one is that the controladapter receives the postback now, not the menu control. ...
CSS Control Adapter Toolkit for ASP.NET 2.0 - ScottGu's Blog asp:Menu> <asp:SiteMapDataSource ID="SiteMapDataSource1" ... control adapters hooked up it renders correctly and fires my menuitemclick handler when clicked. ...
www.timemfg.com/newtime/Bin/Infragistics.WebUI.UltraWebNavigator.v6.2.xml ... to an XmlDataSource or SiteMapDataSource control in addition to a relational database. ... Events for the data binding are fired to the specified menu control. ...



 
All Times Are GMT