Search code examples
asp.netquery-stringcode-behind

Get value from a single link to use it on target page's code behind


Yes title is a little confusing but let me tell you what I have on my mind.

I'm doing a e-store website with ASP.NET as a training project. I got game lists in a DataList on my content div of main master page. These are like "best sellers, latest releases, coming soon" etc.

As you guess, each content with even their css is same, only their code behind changes as sql commands. If I list games by their order count on best sellers, I order them by ID desc etc.

So I tried to WUC it but couldnt do it. That made me to create 3 new page and copy all content and code behinds differently for all of them. It's not professional as you can see.

I need a tip about how my best seller link (like, best-sellers.aspx) can give me a value to use on code behind? I mean, I want one code behind page, so it will have 3 different sql listing codes but I'll only execute one of them with catching referrer page.

How can I do it?


Solution

  • Could you have one page then pass a querysting variable ?

    gameslist.asp?type=bestsellers
    

    then in your code behind

    var pagetype = Rquest.QueryString["type"];
    

    then switch your logic depending on the value of the pagetype variable