2

I have a pure HTML (.html extension) page that posts to a .aspx page that I need to get the multiple selection from. In PHP, this is handled by simply adding the square brackets to the element name and treating it as an array.

<select name="select[]" multiple>
</select>

<input type="checkbox" name="check[]" />

<?php
foreach ($_REQUEST["check"] as $check) {
    // Processing code
}
?>

Is there similar functionality in C#? Or do I have to name every element special? I've been searching online, but everything says to use the HtmlControls or the CheckBoxList classes, which are unavailable because of it being static HTML.

Thanks in advance.

2 Answers 2

1

You do not have to add square brackets to name of the input. Just name it as you want:

<input type="text" name="textBoxes" />
<input type="text" name="textBoxes" />

Then simply use GetValues() in code behind:

string[] values = Request.Form.GetValues("textBoxes");

foreach (var val in values) {
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. That worked perfectly. I knew there had to be a way, but I'm still fairly new to C# so I wasn't sure what it was.
0

If you are using static HTML, you will need to use Javascript to get the values that you want to then pass on to the aspx page

1 Comment

Why in the world would you pass it to JavaScript to send it to any other page? You just use the form submit and set action to the aspx page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.