Pb: passing values between pages using NavigateUrl

Last post 07-06-2009 10:16 AM by tng. 3 replies.

Sort Posts:

  • Pb: passing values between pages using NavigateUrl

    07-02-2009, 9:00 AM
    • Member
      3 point Member
    • tng
    • Member since 06-24-2009, 4:10 AM
    • Posts 26

    Hello,

    I'm not sure if I'm in the right place to post this question, here's my pb:

    I have a login.aspx.cs page where I  get a value & pass it in the url, like this:

    Response.Redirect("Welcome.aspx?group=" + group + "&user=" + Login1.UserName.ToString(), false);

    Then in the Welcome.aspx page I have 3 links: ProjectManagement, SupplierManagement, OrderManagement. Some of them can be shown or hidden, according to the group that I got from the url, as shown:

    <script runat="server">
      protected void Page_Load(Object sender, EventArgs e)
      {
          string group = Request.Params["group"].ToString();
          string user = Request.Params["user"].ToString();
       if (group=="Admin")
       {
        AdminLink.Visible = true;
        BuyerLink.Visible = true;
        DemandeurLink.Visible = true;
       }
       else if (group=="Buyer")
       {
           AdminLink.Visible = false;
           BuyerLink.Visible = true;
           DemandeurLink.Visible = true;
       }
       else if (group == "Demandeur")
       {
           AdminLink.Visible = false;
           BuyerLink.Visible = false;
           DemandeurLink.Visible = true;
       }
       else
       {
           AdminLink.Visible = false;
           BuyerLink.Visible = false;
           DemandeurLink.Visible = false;
       }
      }
      </script>

    <asp:HyperLink id="DemandeurLink" runat="server"
       Text="Gestion des commandes" NavigateUrl='<% "OrderManagement.aspx?group=" + Request.Params["group"]%>'/>

    <asp:HyperLink id="BuyerLink" runat="server"
       Text="Gestion des commandes" NavigateUrl='<% "SupplierManagement.aspx?group=" + Request.Params["group"]%>'/>

    <asp:HyperLink id="AdminLink" runat="server"
       Text="Gestion des commandes" NavigateUrl='<% "ProjectManagement.aspx?group=" + Request.Params["group"]%>'/>

    It means that I want to transfer group variable twice: from the login page to the welcome page, and them from the welcome page to one of 3 links below. The pb is when I click on one of these 3 links, I do not have what I expected, but:

    http://localhost/GDA/%3C%%20%22OrderManagement.aspx?group=%22%20+%20Request.Params[%22group%22]%%3E

    What cause the pb? What have I done wrong?

    I also tried (help from google):

    NavigateUrl='<%#"OrderManagement.aspx?group=" & DataBinder.Eval(Container.DataItem, "group")%>'

    but I got a compile error:

    error CS: 'System.Web.UI.Page' does not have a definition for 'DataItem' and no 'DataItem' extension method accepting
    the first argument with 'System.Web.UI.Page' type can be found (a directive or assembly reference missed?)

    So, what should I do, please help!!!

    Thanks,

  • Re: Pb: passing values between pages using NavigateUrl

    07-04-2009, 7:40 AM
    Answer
    • Member
      73 point Member
    • saurabh2k4mc095
    • Member since 10-03-2008, 8:00 AM
    • New Delhi
    • Posts 18

    NavigateUrl='<%#"OrderManagement.aspx?group=" & DataBinder.Eval(Container.DataItem, "group")%>'


    remove '&' and try again..

    hope it will help.

    if correct the please mark as answer..

    Remember to click “Mark as Answer” on the post, if it helps you. Because It helps others to find the solution

    Thanks.
    ~Saurabh
  • Re: Pb: passing values between pages using NavigateUrl

    07-05-2009, 5:20 PM
    Answer
    • Participant
      1,547 point Participant
    • ctheriault
    • Member since 04-10-2009, 4:33 PM
    • Posts 276

     <% ... %> operator allows you to execute a statement but it does evalute/return an expression to be expanded in your asp. That's why you get the UrlEncoded source string instead of its evaluated form.

    Try <%= ... %> instead and it should work fine.

    <asp:HyperLink id="DemandeurLink" runat="server"
       Text="Gestion des commandes" NavigateUrl='<%= "OrderManagement.aspx?group=" + Request.Params["group"]%>'/>

    If you chose to use <%# ... %> instead, then you also need to call DataBind() form your code behind.

    ----
    Don't forget to mark this posting as an "Answer" if it is helpful to you
  • Re: Pb: passing values between pages using NavigateUrl

    07-06-2009, 10:16 AM
    • Member
      3 point Member
    • tng
    • Member since 06-24-2009, 4:10 AM
    • Posts 26

    Hello, Thanks for your helps, I tried NavigateUrl='<%# "GestionCommande.aspx?groupe=" & DataBinder.Eval(Container.DataItem, "groupe")%>' 

    a) by replacing '&' with:

    nothing => errors: missing ) missing ;

    '+' or ',' => error CS: 'System.Web.UI.Page' does not have a definition for 'DataItem' and no 'DataItem' extension method accepting
    the first argument with 'System.Web.UI.Page' type can be found (a Using directive or assembly reference missed?)

    b) by replacing <%# %> with

    <%= %> => here's what I got when I click on the link

    http://localhost/GDA/%3C%=%20%22OrderManagement.aspx?group=%22%20&%20DataBinder.Eval(Container.DataItem,%20%22groupe%22)%%3E

    c) by replacing NavigateUrl='<%# "GestionCommande.aspx?groupe=" & DataBinder.Eval(Container.DataItem, "groupe")%>' with

    NavigateUrl='<%= "GestionCommande.aspx?groupe=" + Request.Params["groupe"]%>' => here's what I got when I click on the link:

    http://localhost/GDA/%3C%=%20%22OrderManagement.aspx?groupe=%22%20+%20Request.Params[%22groupe%22]%%3E


    That's really strange, s.o has the same pb? Both methods cannot resolve. Here's my solution (it works for my application): I put variables into Session. Here's how it works (to people who do not knows):

    page 1: Session["group"]= group;

    page 2: string group=Session["group"]

    Session variable is still avaible throught out the application (between pages), you can get it at anytime.

    Thanks

Page 1 of 1 (4 items)