Getting Value From Html Radio Button - In Aspx-c# January 15, 2024 Post a Comment I have the following HTML source Solution 1: place your code like this:if (Request.Form["Gender"] != null) { string selectedGender = Request.Form["Gender"].ToString(); } CopyNote that Request.Form["Gender"] will be null if none of the RadioButtons are selected.see the markup below<form id="form1" runat="server" method="post"> <input type="radio" name="Gender" value="male"id="test" checked="checked" /> male <input type="radio" name="Gender" value="female" />female <input type="submit" value="test" /> <asp:Button ID="btn" runat="server" Text="value" /> </form> Copyfor both the buttons i.e input type="submit" and usual asp:button, Request.Form["Gender"] is going to have some value upon PostBack, provided, either of the RadioButtons is selected. And yes, upon PostBack only, i.e. when you hit either of the buttons and not on first load.Solution 2: To start with you will need the form posted the Form collection won't have anything on the page load, so suppose you have a button and you click to submit the form then in the click event handler you can get the selected value with the code you have tried.I guess the collection is null hence the NullReference exception when you access it.Baca JugaHow To Design A Radio Button, Which Looks The Sam In Firefox, Chrome And Ie11Javascript Value Composed Of Several Words [value=dog Crazy]C# Asp.net Radiobuttonlist Within Table: Border Also Creating Border Arount List ItemsIt is better to access it likeif(!string.IsNullOrEmpty(Request.Form["Gender"])) { } CopySolution 3: Use a RadioButtonList<asp:RadioButtonListid="RadioButtonList1"runat="server"><asp:ListItemvalue="male">male</asp:ListItem><asp:ListItemvalue="female">female</asp:ListItem></asp:RadioButtonList>Copyand get the value with RadioButtonList1.SelectedValue; CopySolution 4: if you are working with asp.net make sure that HTML control name by Request.Form contains these ct100$ with the name or id through which you are assessing. check the below example.int rbratebyname = 0; if (Request.Form["ctl00$ContentPlaceHolder1$rate"] != null) { rbratebyname = int.Parse(Request.Form["ctl00$ContentPlaceHolder1$rate"]); } Copy Share You may like these postsDropdownListfor To Be Auto Selected On The Basis Of A Value Of String Asp.net MvcHow To Display ALL The Divs Inside A Parent DIVHow To Make A Comparison Html Table Using Asp Repeater (data Rotation)MimeMap Still Does Not Display My Svg Post a Comment for "Getting Value From Html Radio Button - In Aspx-c#"
Post a Comment for "Getting Value From Html Radio Button - In Aspx-c#"