This is a migrated thread and some comments may be shown as answers.

How to change NavigateUrl at run-time?

5 Answers 179 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Nim
Top achievements
Rank 1
Nim asked on 06 Jan 2011, 10:12 PM
Hello,

I am building a MVC program.  When I test the menu in the View:

    <telerik:RadMenu ID="RadMenu1" runat="server">
        <Items>
            <telerik:RadMenuItem runat="server" PostBack="False" Text="M1-1"
                NavigateUrl="~/home/show?p1=10"  >
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>

it works.  But in my case, I need to change the parameter value "p1" in run-time, depending on the combination of some previous user's inputs.

Ideally, if I can use some variables in the codes such as:

   ... NavigateUrl="~/home/show?p1=<%= Session['magic_number'] %>" ...

this will solve the issue.  However, this code runs into parser error.

I wonder if there is any solution or workaround to address this situation.  Many thanks.

5 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 07 Jan 2011, 03:34 PM
Hello Nim,

To bind the NavigateUrl, you would do something like this:

NavigateUrl='<%# String.Format("~/home/show?p1={0}",Session["magic_number"]) %>'

I hope that helps.
0
Nim
Top achievements
Rank 1
answered on 07 Jan 2011, 06:49 PM
Hello,

When I run the following test in the View:

------
    <% Session["magic_number"] = "2"; %>
    <p>
    Testing - make sure it stores the value: <%= Session["magic_number"] %>
    </p>
    <telerik:RadMenu ID="RadMenu1" runat="server">
        <Items>
            <telerik:RadMenuItem runat="server" PostBack="False" Text="M1-1"
                FocusedCssClass="" SelectedCssClass=""
                NavigateUrl='<%# String.Format("~/home/show?p1={0}",Session["magic_number"]) %>'  >
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>
------

the generated path returns "#" instead of "~/home/show?p1=2".  Am I missing something?

Thank you!
0
Kalina
Telerik team
answered on 17 Jan 2011, 03:47 PM
Hello Nim,

Please note that ASP.NET and ASP.NET MVC are two completely different frameworks.

Let me suggest you use the Telerik Menu for ASP.NET MVC in your MVC application.
You can find the key features of this control demonstrated here.

Kind regards,
Kalina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Paul X
Top achievements
Rank 1
answered on 10 Apr 2011, 06:50 AM

<

 

 

telerik:RadMenuItem runat="server" Value="Home" Text="Home" NavigateUrl='<%# String.Format("~/home/show?p1={0}","hello") %>'>

 



trying to set url at runtime but produces no output just a #..any reason?

ie

<li class="rmItem rmFirst">
<a class="rmLink rmRootLink rmSelected" href="#">
<span class="rmText">Home</span>
</a>
</li>
0
Calleigh
Top achievements
Rank 1
answered on 14 Apr 2011, 05:29 PM
You can use the Menu for ASP.NET MVC instead of implementing the RadMenu for ASP.NET AJAX in your MVC application.
http://demos.telerik.com/aspnet-mvc/menu
Tags
Menu
Asked by
Nim
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Nim
Top achievements
Rank 1
Kalina
Telerik team
Paul X
Top achievements
Rank 1
Calleigh
Top achievements
Rank 1
Share this question
or