Radio check/uncheck in mvc 4 razor - asp.net

I'm trying to make the radio button checked based on the roleId in the ViewBag but no matter what the value is the radio button is always checked.
Here is the razor :
<input type="radio" id="rdResident" class="userType" checked="#(ViewBag.roleId=="5"?"checked":"false")" />

All you need the word "checked". Try...
<input type="radio" id="rdResident" class="userType" #(ViewBag.roleId==5 ? "checked" : "") />

Related

Bootstrap Toggle with ASP.NET

I'm using bootstrap-toggle in one of the forms in ASP.NET:
<input type="checkbox" id="IsValidated" data-toggle="toggle" data-on="Validated" data-off="Not Validated" data-onstyle="success" data-offstyle="danger" value="Y" >
But when switching on the toggle, and check the state of the checkbox in the code behind after posting the form, always I find that the checkbox is not checked!
How to capture the state of the checkbox?
Add name attribute to your checkbox element
<input type="checkbox" name="IsValidated" id="IsValidated" data-toggle="toggle" data-on="Validated" data-off="Not Validated" data-onstyle="success" data-offstyle="danger" value="Y" >
Access the checkbox value on server side using
Request.Form["IsValidated"]

How to Remove character-counter in radio button in materializecss

I need to remove this span tag its come automatically when i click on radio button
I think you used class="with-gap" in <input> like this :
<input class="with-gap" name="group3" type="radio" checked />
Remove it like this :
<input name="group3" type="radio" checked />
And your problem will be solve. Read here for more info.

Select radio button from RadioButtonList with URL

I have a web form with a dynamically created RadioButtonList, a topic text box, a message text box, and a submit button. I need my monitoring from Solarwinds to be able to submit the form using the post method. I'm using QueryString for the text boxes, but I'm lost with the radio buttons. Is there a way to select a radio button via the URL and submit the form? Here is a sample of the generated HTML:
<input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="value 1" /><label for="RadioButtonList1_0">Topic 1</label>
<input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="value 2" /><label for="RadioButtonList1_1">Topic 2</label>
This is all I needed. Having a slow day today!
RadioButtonList1.SelectedValue = Request.QueryString["selected"];
www.myurl.com?selected=value 1

HTML Radiobuton values in ASP.NET

I'm having some real problems with a group of HTML Radiobuttons when I try to pass the selected values back and forth between JavaScript and ASP.NET.
<input type="radio" id="radio1" name="markerSel" value="1" checked=true />
<input type="radio" id="radio2" name="markerSel" value="2" />
<input type="radio" id="radio3" name="markerSel" value="3" />
To begin with, the form loads with these radiobuttons and a user selects a value and submits the ASP.NET form. To get the value of the selected option on the server-side I have tried;
string selVal = Request.Form["markerSel"];
//always returns "1", regardless of the selection made.
And also tried ASP.NET's FindControl method (recursively too), and I just get null.
I want to be able to set the value of this radiobutton group via JavaScript and Asp.NET and be able to read from both environments.
Any help would be appreciated.
Thanks
Is there a reason why you don't use ASP.NET radio buttons instead of <input type=radio />?
If you use
<asp:RadioButton id="radio1" runat="server" Checked="true" />
<asp:RadioButton id="radio2" runat="server" />
<asp:RadioButton id="radio3" runat="server" />
You will be able to access them server-side by doing this.radio1.Checked
If you want to access your elements via javascript, you can do a document.getElementById('radio1') and you will get the DOM element that way.
If you want to use jQuery, you can access the radio buttons with
$('#radio1')
If you want to test if the radio button is checked, you can use
if ($("#radio1").is(':checked')) {//...
hmmm... I would try changing the line to:
string selVal = Request.Form("markerSel");

Checkbox validation for multiselection

i need to restrict users selecting check boxes multiple times, only one check box should be seleted in my asp.net form ,
i am not using a checkbox list
Please help
Use something like this:
<input type="radio" name="foo" value="bar1" id="bar1"> <label for="bar1">Bar One</label>
<input type="radio" name="foo" value="bar2" id="bar2"> <label for="bar2">Bar Two</label>
<input type="radio" name="foo" value="bar3" id="bar3"> <label for="bar3">Bar Three</label>
Use Javascript. Call a method whenever a CheckBox is clicked that takes the ID of that CheckBox as an argument and then unchecks all other Checkboxes in the given context.

Resources