I got 2 imagebuttons. When I click imagebutton "melk", i want response.redirect to have the url
Default.aspx?anledning=an&matintoleranse=melk.
Then, when I click imagebutton "egg", I want the url to show Default?aspx?anledning=an&matintoleranse=melk&mati ntoleranse=egg
Then, when I click imagebutton "egg" again, I want the url to show Default?aspx?anledning=an&matintoleranse=melk
Unfortunately, my code does not show it, but instead it shows Default.aspx?anledning=an&matintoleranse=melk,e gg&matintoleranse=melk when i click "egg" again.
I got 2 imagebuttons. When I click imagebutton "melk", i want response.redirect to have the url
Default.aspx?anledning=an&matintoleranse=melk.
Then, when I click imagebutton "egg", I want the url to show Default?aspx?anledning=an&matintoleranse=melk&mati ntoleranse=egg
Then, when I click imagebutton "egg" again, I want the url to show Default?aspx?anledning=an&matintoleranse=melk
Unfortunately, my code does not show it, but instead it shows Default.aspx?anledning=an&matintoleranse=melk,e gg&matintoleranse=melk when i click "egg" again.
Hi dolli,
Based on my understanding, what you need is that according to the order of the ImageButton clicked like imgBtnMelk -> imgBtnEgg -> imgBtnEgg, the URL should display in this train:
1. Default.aspx?anledning=an&matintoleranse=melk
2. Default.aspx?anledning=an&matintoleranse=melk&matintoleranse=egg
(I deleted the space might be unexpected in the last matintoleranse and changed the question mark to dot between Default and aspx)
3. Default.aspx?anledning=an&matintoleranse=melk
(Also changed the question mark to dot between Default and aspx)
If I have misunderstood you, please feel free to let me know.
However, the last URL you get now is "Default.aspx?anledning=an&matintoleranse=melk,egg&matintoleranse=egg" which makes the mistake.
I think the problem is caused by the if statement gives a wrong judgement at line 35. When the QueryString has more than one parameter with the same name, it will return a string list splited with the comma, like "melk,egg" in your condition for example.
So, I suggest you modifying the code in line 35 to the one below and have another try.
34 if (Request.QueryString[var] !=
"" & var ==
"matintoleranse"
35 & !Request.QueryString[var].Split(",".ToCharArray()).Contains("egg"))
Here is the solution... I did it in vb... i'm sure you can easily convert it into C#....
Partial Class Default
Inherits System.Web.UI.Page
Dim strquery As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
strquery = Request.ServerVariables("QUERY_STRING")
End Sub
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk")
End Sub
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
If (strquery.Contains("matintoleranse=melk") And Not strquery.Contains("matintoleranse=egg")) Then
Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk&matintoleranse=egg")
ElseIf strquery.Contains("matintoleranse=egg") Then
Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk")
ElseIf strquery = "" Then
Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk")
End If
End Sub
End Class
Hope this helped you...
Thanks
Swapna
Please click "mark as answer" if this post helped you.
dolli
Member
15 Points
25 Posts
How do i create the right url? (including Request.Querystring)
Sep 16, 2008 04:50 PM|LINK
Hi!
I got 2 imagebuttons. When I click imagebutton "melk", i want response.redirect to have the url Default.aspx?anledning=an&matintoleranse=melk.
Then, when I click imagebutton "egg", I want the url to show Default?aspx?anledning=an&matintoleranse=melk&mati ntoleranse=egg
Then, when I click imagebutton "egg" again, I want the url to show
Default?aspx?anledning=an&matintoleranse=melk
Unfortunately, my code does not show it, but instead it shows Default.aspx?anledning=an&matintoleranse=melk,e gg&matintoleranse=melk when i click "egg" again.
What's wrong?
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); }dolli
Member
15 Points
25 Posts
Re: How do i create the right url? (including Request.Querystring)
Sep 16, 2008 08:46 PM|LINK
Still got this problem...
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: How do i create the right url? (including Request.Querystring)
Sep 18, 2008 04:09 AM|LINK
Hi dolli,
Based on my understanding, what you need is that according to the order of the ImageButton clicked like imgBtnMelk -> imgBtnEgg -> imgBtnEgg, the URL should display in this train:
If I have misunderstood you, please feel free to let me know.
However, the last URL you get now is "Default.aspx?anledning=an&matintoleranse=melk,egg&matintoleranse=egg" which makes the mistake.
I think the problem is caused by the if statement gives a wrong judgement at line 35. When the QueryString has more than one parameter with the same name, it will return a string list splited with the comma, like "melk,egg" in your condition for example.
So, I suggest you modifying the code in line 35 to the one below and have another try.
Best Regards,
Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
swapnasamson...
Member
410 Points
299 Posts
Re: How do i create the right url? (including Request.Querystring)
Sep 18, 2008 04:43 AM|LINK
hi doli,
Here is the solution... I did it in vb... i'm sure you can easily convert it into C#....
Partial Class Default Inherits System.Web.UI.Page Dim strquery As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load strquery = Request.ServerVariables("QUERY_STRING") End Sub Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk") End Sub Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click If (strquery.Contains("matintoleranse=melk") And Not strquery.Contains("matintoleranse=egg")) Then Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk&matintoleranse=egg") ElseIf strquery.Contains("matintoleranse=egg") Then Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk") ElseIf strquery = "" Then Response.Redirect("Default.aspx?anledning=an&matintoleranse=melk") End If End Sub End ClassHope this helped you...
Swapna
Please click "mark as answer" if this post helped you.
dolli
Member
15 Points
25 Posts
Re: How do i create the right url? (including Request.Querystring)
Sep 18, 2008 10:04 AM|LINK
To Shengqing Yang - MSFT: You understood correctly. I tried your code, and it says System.Array does not contain a definition for Contains.
To swapnasamsonvarkey: I need the code more smooth because in reality there's more imagebuttons, but thanks for trying.
Conclusion: I wish this code would work, so if you still would like to help me make it work, then I'll follow it up.
Anyway, I got the answer to this problem in another format.
http://forums.asp.net/t/1320885.aspx
Thanks for trying to help!