navigateurl in meny contro

In VS2005 ASP.NET 2.0 sqlserver 2000.
I have a menu control of 10 menuitems that is defined in a master page.
each menuitem has a navigateURL to a page of the master.
this is a definition of a menuitem:
 
<asp:MenuItem NavigateUrl="CandSeminar.aspx" Text="Seminar" Value="Seminar" ></asp:MenuItem>
I would like to add a querystring to the navigateurl that is defined in a Label in the page. (label1.text)
How do I write it?
ANAT2403Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

enwhyseeCommented:
You could use some codebehind to accomplish this. You'd also need to set the ID= of the menuItem as follows:

<asp:MenuItem ID="myMenuItem" NavigateUrl="CandSeminar.aspx" Text="Seminar" Value="Seminar"  />

Example code in your codebehind:

using System.Web.UI.WebControls;

. . .

MenuItem myMenuItem;
Label label1;

. . .
This would probably go into the OnLoad event of the page:
myMenuItem.NavigateUrl = "CandSeminar.aspx?key=" + Server.UrlEncode(label1.Text);


0
enwhyseeCommented:
Note that Server.UrlEncode is necessary to put whatever is in label1.Text into a format suitable to be in a URL (for example, to encode the spaces to %20)
0
ANAT2403Author Commented:
Hi
The ID property does not exist in menuitem but I guess you ment the following:
            mpMenu.Items[1].NavigateUrl = "CandSeminar.aspx?key=" + Server.UrlEncode(mpLabel.Text);
The problem is that I can't put this line in the formload of the masterpage because in this time the controls are empty.
I thought of putting in in the event of MenuItemClick but I discovered that this event does not happen. No events take place in the master page and it goes directly to the page of the placeholder.
Where should I put it?
By the way should I write the word key in the navigateurl or I can write the word querystring?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

enwhyseeCommented:
Ah, you're right. There is no ID property on the MenuItem, but it can be accessed exactly as you mentioned :)

I see -- so the value of mpLabel gets set during OnLoad of the page itself?

If that is the case, could you try putting this code into the OnPreRender event of the master page?

Article from MS:
http://msdn2.microsoft.com/en-US/library/dct97kc3.aspx
0
enwhyseeCommented:
Also, you don't have to use the word "key". It could be anything, querystring is good too.
0
ANAT2403Author Commented:
Hi,
First I don't kmow how to invoke the preRender event of the masterpage.
Can you tell me?
Second I will explain my problem deeper:
In the pageload of the content page I read a value from the master page. I could read it ok until I made a
change in my program in which I call the content of the masterpage with the querystring.
The thing is that I call one content and then through a menu that is defined in the master page I move to another content. but now when I move from one content to another I loose the values of the master page.
I am not sure I explained it good.
Thankyou
Anat
0
enwhyseeCommented:
The PreRender method will get invoked automatically by ASP.NET. You just need to add some handling for it. If you open the master page in design mode and press F4 (i.e. bring up the Properties window), and then click on the golden looking arrow, double click on PreRender to add a handler. Then you can type your code in there.

I see what you mean. So you browse to:
   http://machine/your.aspx?querystring=Hello
which works fine on the first page ... but as you click a link, the "querystring=Hello" part is lost? That is normal behavior, and you are trying to solve it in the correct way. Another way would be to try to set a cookie in the browser, but using the query string is a lot more straightforward.

Does mpLabel live on the master page?
0
ANAT2403Author Commented:
mplabel is on the master page.
I still have problems with invoking the prerender:
When I press the F4 for the properties in design mode of the master page, I see it deal with the DOCUMENT
and in this case ther is no golden looking arrow? how come?
0
ANAT2403Author Commented:
OK I almost solve all the problems here by using the event of the menu:
 Menu1_MenuItemClick(object sender, MenuEventArgs e) and give velue to:
e.Item.NavigateUrl = ..........
The only problem left is that I have to press the menuitem TWICE!!!!! in order to get the new choice. When I press the first time it goes to the MenuItemClick and set the new NavigateUrl but it does not switch to the new menuitem. Only
After I press the second tome it moves to the new choice. Why is that?
0
ANAT2403Author Commented:
I found the solution.
The solution is to use Response.Redirect.
I close the question.
0
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.