I am dynamically adding and removing items from a menu control depending on what is going on in my web application. The problem is, the menu control doesn't want to refresh with the new items, I am assuming, because the page has not been posted back. The code works in a button click, but I am needing this to run in a separate event that does not do a page postback. Is there a way to force a page postback or to call some sort of refresh on the control? my ASP.NET skills are severely lacking...
If it's a data-bound item, in your codebehind just call the Menu.DataBind() function. Should refresh just the object with any new information in it without causing a complete postback.
The menu is static, not databound. I wouldn't mind doing a complete postback (since I assume thats why the button click works), just don't know how to call one (or execute one) through code.
Check the properties of the button, see if there's an option that has something to do with postbacks. I know in the databound items the Smart Tag has an option called Enable Auto Postback, which takes care of that... not totally sure about the buttons.
I'm not using a button, I am wanting to do it without a button in a different sub. It works with a button, but only because the button posts back which refreshes the menu control. The menu control doesn't have any properties or methods regarding postbacks. I dont mind doing a postback like the button does but I don't know how to go about doing it. The items are what they need to be in the code, its just that the menu control isn't refreshed to reflect those changes because nothing triggers a postback in the sub I am doing it and the menu control doesn't have any sort of postback capabilities (that I see).
I ended up just using Hyperlink controls instead and switching out the link url's and text, which works, but I would prefer to use the menu control. If anyone knows of a way to refresh the menu control after adding/removing items, feel free to respond...
Actually no, the items are being switched out in response to some other event in the application. When that event occurs, it changes the items in the menu, and I need the menu to then refresh...
Its just using the Items.Remove and Items.Add method of the menu control. It is a seperate control code that runs on a click (another menu at the top), which then changes the menu items on the left depending on the selection, using the .Add and .Remove method of the menu control. However, I need the control to refresh after that. The items are being added and removed successfully because the output count of the items in the control are correct, however, the control does not refresh, which I need it to do. Hence the problem. It seems that if the control was databound, it would do it automatically, but I am not using databinding.
Well it would work if the map items in the first one don't have links defined for them, but mine all refer to URL's of the page with different parameters in a query string. Once you add a URL to the items in the menu the code doesn't refresh the other menu.
Lewisburg, PA "Next year Raiders in the Super Bowl"
Posts
1,310
Re: Dynamic MenuItem changes ... Postback?
what if you added a helper class that you would run upon the page load event then within the helper class wire it up so you pass in the side menu and an additional parameter that you'd get from the querystring and setup the side menu... you could also do this by way of creating a new page base class and perform this in there as well
Derek - Using VS 2008 99% of the time and VS 2003 1% of the time