menu postback not working

G

Guest

My asp.net 2005 menu control has items with nothing in navigateUrl - meaning
it should postback when an item is selected. I have code in the Page_Load
which is supposed to call a method based on the selected menu item.

if (this.Menu1.SelectedItem.Value.Equals("1"))
processA();
if (this.Menu1.SelectedItem.Value.Equals("2"))
processB();

This does not work the first time the menu item is selected. It does work
the second time the menu item is selected.
I guess I STILL do not understand postback. Shouldn't this work for the
first selection?
Thanks
 
B

Ben Dewey

set the autopostBack = true on the Menu control. Also you should put the
posted code in the Menu1_Click event.
 
G

Guest

I do not see an autopostBack either throught the property sheet or though the
object. Also, I must have the menu selected item value in the Page_Load as
it is here that I must know which of my load routines to call (not in the
click event).
Any help is greatly appreciated.
 
B

Ben Dewey

What kind of MenuControl are you using? Why do you need to run that code on
the Page_Load, when you need the user to click something anyways

It would be better to use:

void Page_Load(sender, e)
{
if (!Page.IsPostBack)
ProcessDefault();
}

void Menu1_Click(sender, e)
{
if (this.Menu1.SelectedValue.Value == "1")
ProcessA();
if (this.Menu1.SelectedValue.Value == "2")
ProcessB();
}
 
G

Guest

The menu control is the standard menu control selected from the navigation
list of controls from the toolbox in VS 2005.
I must have the selected value in page_load because it is a report choice
and I must know what report they are requesting. I can only build the report
at load time (as I understand it).
 
Joined
Dec 16, 2010
Messages
1
Reaction score
0
To Enable/Disable postbacks on Menu Items without a NavigateURL use the .Selectable property.

myMenuItem.Selectable = True

tells the menu to do a postback on the menuitem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top