Response.Redirect & Request.QueryString - creating the right url (with code)

Joined
Sep 15, 2008
Messages
2
Reaction score
0
Hi!

I got two imagebuttons. When I click imagebutton "melk", I would the url to show Default.aspx?anledning=an&matintoleranse=melk.

Then, when I click imagebutton "egg", I would like the url to show Default?aspx?anledning=an&matintoleranse=melk&matintoleranse=egg

Then, when I click imagebutton "egg" again, I would like the url to show
Default?aspx?anledning=an&matintoleranse=melk

Instead, with my code, it shows Default.aspx?anledning=an&matintoleranse=melk,egg&matintoleranse=melk when I cilck the imagebutton "egg" again.

What's wrong?

My code:
Code:
protected void imgBtnMelk_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        string anledning = lblanledning.Text;
        string url = "Default.aspx?anledning=an";
        string check = "empty";

        foreach (string var in Request.QueryString)
        {
            if (Request.QueryString[var] != "" & var == "matintoleranse" 
                & Request.QueryString[var] != "melk")
            {
                url += "&matintoleranse=" + Request.QueryString[var];
            }
            if (Request.QueryString[var] == "melk")
            {
                check = "removed";
            }
        }
        if (check != "removed")
        {
            url += "&matintoleranse=melk";
        }
        Response.Redirect(url); 
    }
    protected void imgBtnEgg_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {

        string anledning = lblanledning.Text;
        string url = "Default.aspx?anledning=an";
        string check = "empty";

        foreach (string var in Request.QueryString)
        {
            if (Request.QueryString[var] != "" & var == "matintoleranse"
                & Request.QueryString[var] != "egg")
            {
                url += "&matintoleranse=" + Request.QueryString[var];
            }
            if (Request.QueryString[var] == "egg")
            {
                check = "removed";
            }
        }
        if (check != "removed")
        {
            url += "&matintoleranse=egg";
        }
        Response.Redirect(url); 
    }
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,646
Members
47,249
Latest member
AlizaMoniz

Latest Threads

Top