I'm trying to find a way to generate routes for ASP.NET Web Forms in the declarative ASPX part.
This example works but it doesn't format the route properly in the form of /name/value/ but instead does /name/value?param2=0.
<asp:HyperLink ID="EventLink" NavigateUrl="<%$RouteUrl:param=myparan, param2=0 %>" Text="More" runat="server" />
I created a second method as shown below, thinking I could pull out the routevalues
<a href="<%# GetMyRoute(Page) %>") %>">
GetMyRoute tries to pull out the route values but RouteData is always nulls:
page.RouteData.Values["MyParam"]
I have 2 specific questions.
How do I pass the routed values into my GetMyRoute method? What is the syntax that allows me too do this GetMyRoute("<%$RouteValue:MyRoute%>).
Is there some way for me to read the values using the RouteData object? Again, it returns null but the values are there in the Page_Load.
How would I pass in a variable "<%$RouteUrl:param=myparan, param2=0 %>" for one of the params, say a property on the page?
** Partial Solution *
I found the following code. However, how does one pass in a page RouteValue as a param?
<asp:HyperLink ID="HyperLinkClient" runat="server"
NavigateUrl='<%# GetRouteUrl("ClientRoute", new {ClientID = Eval("ClientID")}) %>' >
Go to Client details
</asp:HyperLink>
The following does NOT work because RouteData is null.
<asp:HyperLink ID="HyperLinkClient" runat="server"
NavigateUrl='<%# GetRouteUrl("ClientRoute", new {ClientID = RouteData.Values["ClientId"] }) %>' >
Go to Client details
</asp:HyperLink>
Update The central "crux" of this question is how to pass in route parameters that were passed into the page without resulting to code-behind solution. Notice that RouteData.Values is null/empty when checked in the configuration shown above. I need to test the <%= syntax to see if that fixes it. The solutions proposed so far don't deal with the central issues.