开发者

use QueryString with asp:MenuItem

开发者 https://www.devze.com 2023-02-20 14:45 出处:网络
How do I pass a string with QueryString from a MenuItem? I tried /UserDisplay.aspx?UserName=<%(String)Session[\"sessUserName\"]%>\"

How do I pass a string with QueryString from a MenuItem? I tried

/UserDisplay.aspx?UserName=<%(String)Session["sessUserName"]%>"

But this returned errors..

Is there a way to do this within the menuitem, or do I have to do it in the OnClick event?

As per requests, more code:

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" 
                    EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal" 
                    onmenuitemclick="NavigationMenu_MenuItemClick">
        <Items>
              <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
              <asp:MenuI开发者_如何学Pythontem NavigateUrl="~/UserManagement/UserManagement.aspx" Text="User Management">
                   <asp:MenuItem NavigateUrl="~/UserManagement/UserManagement.aspx" Text="Manage Users" />
                   <asp:MenuItem NavigateUrl="~/UserManagement/UserDisplay.aspx" Text="New User"/>
              </asp:MenuItem>
              <asp:MenuItem NavigateUrl="~/UserManagement/UserDisplay.aspx?UserName=<%(String)Session["sessUserName"]%>" Text="FYI Access Request"/>
        </Items>
</asp:Menu>


Try this:

<asp:MenuItem NavigateUrl='~/UserManagement/UserDisplay.aspx?UserName=<%=(String)Session["sessUserName"]%>' Text="FYI Access Request"/>

I haven't worked with WebForms as much lately, but I think you need to use the <%= %> tag (as opposed to <% %>). I also recall some issues where using single quotes (') instead of double-quotes fixed something, but that may or may not be an issue here.

Edit

It sounds like you may need to take care of this in the code-behind:

public void MyAccountLinkInit(object sender, EventArgs args)
{
    ((MenuItem)sender).NavigateUrl = 
        "~/UserManagement/UserDisplay.aspx?UserName=" + Session["sessUserName"];
}

... and wire up this handler like this:

<asp:MenuItem OnInit="MyAccountLinkInit" Text="FYI Access Request" />


<script type="text/javascript">
     function GoToPage(url) {
         window.location = url + '?ins=<%=cid %>';
         return false;
     }

 </script>
<asp:MenuItem Text="FINANCIAL SUMMARY" NavigateUrl="javascript:GoToPage('ClientMainView.aspx');"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消