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:
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: