1

I want to post checkbox values to server using html. But my code retrieves nothing. Please help.

<form action="Default2.aspx" method="post" >
<input type="checkbox" name="attempt" value="101"> I'st attempt<br>
<input type="checkbox" name="attempt" value="102" checked> 2nd attempt<br>
<input type="submit" value="Submit">
</form>
sashkello
  • 17,306
  • 24
  • 81
  • 109
nsds
  • 961
  • 4
  • 13
  • 39

3 Answers3

0

They need ID's so they can be referred to and if this is a Web Forms website you need to also have the attribute runat="server" for both of them otherwise you won't be able to access them.

Gabriel Sadaka
  • 1,748
  • 1
  • 15
  • 19
  • I'st attempt
    2nd attempt
    LIKE THIS ??
    – nsds May 14 '13 at 04:26
  • close you also need runat="server" on the checkboxes like this:
    I'st attempt
    2nd attempt
    – Gabriel Sadaka May 14 '13 at 04:34
  • @gabriel - use runat="server" only when you want to access that control on server side . above code will work without runat attribute also – Pranav May 14 '13 at 04:36
  • I find that to be one of the easiest ways to deal with form data on the server side when using Web Forms. – Gabriel Sadaka May 14 '13 at 04:37
  • but it shows " System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster." – nsds May 14 '13 at 04:40
  • 1
    Submitting the form posts all the form to the server ..so need to give runat attribute unless necessary – Pranav May 14 '13 at 04:43
0

ASP.NET Page already has form element in the root, and you don't have insert it by self. If you use native HTML element in your ASP.NET page or control, you can get their values by using Request Object. See simple example here How-get-input-text-value-server-side-c.aspx

0

In plain HTML forms, checkbox input controls don't get included in the submission at all if the user left them unchecked. See this question: Does <input type="checkbox" /> only post data if it's checked?

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170