I’m trying to loop through a bunch of checkboxes i have created on my aspx page. I would like to get all the values, and parse them to a string to send to another page as post variables. This is what i have so far:
aspx page:
<div class="ReportsCustomBox"><asp:CheckBox ID="CheckBox0" runat="server" /> Name</div>
<div class="ReportsCustomBox"><asp:CheckBox ID="CheckBox1" runat="server" /> Training Year</div>
<div class="ReportsCustomBox"><asp:CheckBox ID="CheckBox2" runat="server" /> Continuity Clinic</div>
etc...
aspx.vb file:
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Submit.Click
Dim targetURL As String
targetURL = "report.aspx?"
' This is the part i can't figure out.
' For Each checkbox on page
'if checkbox is checked
'targetURL &= checkboxid & "=true&"
End Sub
My goal is to build another page that will then check these values using Querystring variable, and build a listview out of them. (a report page, that basically lets the user select checkboxes of the columns they want to see on the report)
Any help, or direction is very much appreciated!
Thanks!
Not directly an answer to your question, but unless you have a specific reason not to, you should just POST the form to the other page directly. Don’t bother messing around with the code behind which will be fragile and error-prone.
Use the Button.PostbackUrl property to change the page you’re posting to
And in the code-behind of the other page use
Request.Formto access the posted values.Depending on your situation, you can even strongly-type the previous page to make accessing properties and values easier. http://dotnettipoftheday.org/tips/strongly-typed-access-to-previous-page.aspx