2

I have checkboxes that I have created using Literal now on postback I get the checkboxes which are checked in the Request.form.Allkeys. However I don't know how to read those values how can I use them? how can I count how many values are in there and how can I find some values in there example I want to find if the request.forum.allkey contain forumaName0 ..

thank you

Michael Eakins
  • 4,149
  • 3
  • 35
  • 54
Ehsan Kayani
  • 113
  • 3
  • 3
  • 7

2 Answers2

6

Assuming you have these checkboxes in your aspx page:

<input id="Checkbox1" type="checkbox" name="forumaName0" />
<input id="Checkbox2" type="checkbox" name="forumaName1" />
<input id="Checkbox3" type="checkbox" name="forumaName2" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

You should be able to iterate through all the keys and check if the desired checkbox is checked:

protected void Button1_Click(object sender, EventArgs e)
{
    foreach (string key in Request.Form.AllKeys)
    {
        Response.Write(key + "<br />");
    }

    Response.Write("Contain forumaName0? - " + Request.Form.AllKeys.Contains("forumaName0"));
}

EDIT - Screenshot for downvoter: alt text

bla
  • 5,350
  • 3
  • 25
  • 26
1

A quick FYI, in regards to the Contains method mentioned by Lee Sy En and AsifQadri: make sure you have System.Linq in your assembly references if you want to use it (or any of the other IEnumerable extension methods shown in the screenshot above).

Cobra
  • 352
  • 3
  • 12