0

How can I add required to one of the input fields which I believe is needed to enable JQuery Valiadation on a radio button group.

I can add required to the RadioButtonList control by doing the following

rbSeverity.Attributes.Add("required","");

But how can this attribute be added to one of the inputs that is generated from the <asp:ListItem> control?

<asp:RadioButtonList ID="rbSeverity" RepeatDirection="Horizontal" RepeatLayout="Flow"
                                runat="server" >
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
</asp:RadioButtonList>

1 Answer 1

2

You can do this using jQuery:

$(function () {
    $('#<%= rbSeverity.ClientID %> input').attr('required', '');
});

The above code will insert all the required attribute to all the input inside the radio button list.

Sign up to request clarification or add additional context in comments.

Comments

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.