tags:

views:

1222

answers:

3

I'd like to build a query string based on values taken from 5 groups of radio buttons.

Selecting any of the groups is optional so you could pick set A or B or both. How would I build the querystring based on this? I'm using VB.NET 1.1

The asp:Radiobuttonlist control does not like null values so I'm resorting to normal html radio buttons. My question is how do I string up the selected values into a querystring

I have something like this right now:

HTML:

<input type="radio" name="apBoat" id="Apb1" value="1" /> detail1
<input type="radio" name="apBoat" id="Apb2" value="2" /> detail2

<input type="radio" name="cBoat" id="Cb1" value="1" /> detail1
<input type="radio" name="cBoat" id="Cb2" value="2" /> detail2

VB.NET

Public Sub btnSubmit_click(ByVal sender As Object, ByVal e As System.EventArgs)
  Dim queryString As String = "nextpage.aspx?"

  Dim aBoat, bBoat, cBoat bas String

  aBoat = "apb=" & Request("aBoat")
  bBoat = "bBoat=" & Request("bBoat")
  cBoat = "cBoat=" & Request("cBoat ")


  queryString += aBoat & bBoat & cBoat

  Response.Redirect(queryString)

End Sub

Is this the best way to build the query string or should I take a different approach altogether? Appreciate all the help I can get. Thanks much.

A: 

You could use StringBuilder instead of creating those three different strings. You can help it out by preallocating about how much memory you need to store your string. You could also use String.Format instead.

If this is all your submit button is doing why make it a .Net page at all and instead just have a GET form go to nextpage.aspx for processing?

Jon
Remember to Include System.Text if you want to use StringBuilder.
Martín Marconcini
+1  A: 

The easiest way would be to use a non-server-side <form> tag with the method="get" then when the form was submitted you would automatically get the querystring you are after (and don't forget to add <label> tags and associate them with your radio buttons):

<form action="..." method="get">
    <input type="radio" name="apBoat" id="Apb1" value="1" /> <label for="Apb1">detail1</label>
    <input type="radio" name="apBoat" id="Apb2" value="2" /> <label for="Apb2">detail2</label>

    <input type="radio" name="cBoat" id="Cb1" value="1" /> <label for="Cb1">detail1</label>
    <input type="radio" name="cBoat" id="Cb2" value="2" /> <label for="Cb2">detail2</label>
</form>
Ian Oxley
A: 
cjheath