A form helper function that simplifies setting HTML listvalues to server PostBack values with expressions. This function returns checked="checked" when the form value matches the provided value.

This method aims to make it easier to use static HTML and reassign postback values more easily. Without this function the expression would have to use an IIF() function and the following code is a little easier to read and write:

<select id="OutputType" name="OutputType" size="1" class="form-control">
    <option value="Html" <%= Request.FormSelected("OutputType","Html") %> >Html</option>
    <option value="PDF" <%= Request.FormSelected("OutputType","PDF") %> >PDF</option>
    <option value="XML" <%= Request.FormSelected("OutputType","XML") %> >XML</option>
    <option value="JSON" <%=Request.FormSelected("OutputType","JSON") %> >JSON</option>

The above will default to the first selected item when there's no postback or the form variable is not found. If you want to provide a preselected value then you can pass an optional model value:

<select id="OutputType" name="OutputType" size="1" class="form-control">
    <option value="Html" <%= Request.FormSelected("OutputType","Html", poParms.OutputType) %>>Html</option>
    <option value="PDF" <%= Request.FormSelected("OutputType","PDF", poParms.OutputType) %>>PDF</option>
    <option value="XML" <%= Request.FormSelected("OutputType","XML", poParms.OutputType) %>>XML</option>
    <option value="JSON" <%=Request.FormSelected("OutputType","JSON", poParms.OutputType) %>>JSON</option>
o.FormSelected(lcFormKey, lcValue, lcModelValue)

Return Value

If the lcValue matches the Form Var or Model Value, selected="selected" otherwise "".


The name of the form variable.

The value to match. If the Form key matches the value specified the value

Value used when the request is not a POST back or the lcFormKey doesn't exist.

See also:

Class wwrequest

© West Wind Technologies, 1996-2022 • Updated: 03/24/16
Comment or report problem with topic