Doubt Postbackurl

Asked

Viewed 260 times

2

I’m trying to use the PostBackUrl in a LinkButton within the DataList.

Tried the following, partially successfully.

<asp:LinkButton ID="linkBtnMarca" CommandArgument='<%# Eval("Marca") %>' **PostBackUrl='<%# string.Format("~/User/Produtos.aspx?Marca={0}", Eval("Marca")) %>'** runat="server" OnClick="linkBtnMarca_Click"><%# Eval("Marca") %></asp:LinkButton>

The link in the address bar actually changes depending on the tag when we click on LinkButton, example User/Produtos.aspx?Marca=Bosch, but let’s imagine that we don’t want to click on LinkButton and we want to automatically go to the link User/Produtos.aspx?Marca=Bosch, how can I do that? Since I don’t go to LinkButton, doesn’t work.

Thank you.

EDIT:

Code Behind Marca

        LinkButton lnksender = (LinkButton)sender;
        Session["Marca"] = Convert.ToString(lnksender.CommandArgument);
        lblInfo.Visible = true;
        lblInfos.Visible = true;
        lblInfoGet.Visible = false;
        lblInfosGet.Visible = false;
        lblInfoPesquisa.Visible = false;
        lblInfo.Text = "A filtrar pela marca: ";
        lblInfos.Text = Convert.ToString(Session["Marca"]);
        MultiViewContent.DataBind();
        ViewGridView.DataBind();
        ViewListView.DataBind();
        DataListCategorias.DataBind();
        DataListMarcas.DataBind();

1 answer

2


<asp:LinkButton> generates a link within a <form> with action = POST. I think a simple link using GET already solves everything:

<a href="~/User/Produtos.aspx?Marca=<%# Eval("Marca") %>"><%# Eval("Marca") %></a>

EDIT

After inserting the link as above, change:

    LinkButton lnksender = (LinkButton)sender;
    Session["Marca"] = Convert.ToString(lnksender.CommandArgument);

For:

    Session["Marca"] = Request.QueryString["Marca"];
  • I put it in what part? ?

  • Num <button>? In theory yes, because you’re using Session, in which it is filled alone by queryString.

  • What I wanted is a direct link to that Brand, that is to put in HTML User/Products.aspx? Brand=Bosch and go straight to that brand.

  • I tried your solution by removing the LinkButton and it didn’t work

  • What I want is for each brand to have its own link or when I create a category, "automatically create" a dynamic link to automatically go to that brand.

  • @Chiraggeiantilal Try generating a link outside the DataList just as a test, the way I put it in the answer. Make sure it works. runat = server may be influencing the completion of Session[].

  • Would that be? <a href="~/User/Produtos.aspx?Marca=<%# Eval("Marca") %>"><%# Eval("Bosch") %></a>

  • Actually for this test you don’t need the Eval. See also that I modified the answer.

  • Is there any chance Session["Marca"] = "Bosch";&#xA; on the page Load and also Session["Marca"] = Request.QueryString["Marca"]; User/Produtos.aspx?Marca='MarcaPeca' show only products from MarcaPeca.

  • Yes, you can define a default without problems. For example, if Request.QueryString["Marca"] empty.

  • At the moment I have like this in Load: if (!IsPostBack)&#xA; {&#xA; Session["Marca"] = "Bosch";&#xA; } E also place in Load Session["Marca"] = Request.QueryString["Marca"]; and access the link User/Produtos.aspx?Marca='MarcaPeca' will only return the brand products Bosch.

  • 1

    It’s solved. if (Request.QueryString["Marca"] == null)&#xA; {&#xA; Session["Marca"] = "Bosch";&#xA; }&#xA;&#xA; else&#xA; {&#xA;&#xA; Session["Marca"] = Request.QueryString["Marca"];&#xA; &#xA; }

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.