开发者

How to read Values from Request.form.Allkeys

I have checkboxes that I have created using Literal now on postb开发者_JAVA百科ack 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


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:

How to read Values from Request.form.Allkeys


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜