I am having a strange problem with the state of radiobutton with asp.net enabled.
Code on the .aspx page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="testradioButton.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#radYes').change(function () { gererEtat(); }); $('#radNo').change(function () { gererEtat(); }); }); function gererEtat() { $('#radDisabledYes').prop('disabled', !$('#radYes').prop('checked')); $('#radDisabledNo').prop('disabled', !$('#radYes').prop('checked')); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:radiobutton ID="radYes" runat="server" GroupName="test" Text="yes"></asp:radiobutton> <asp:radiobutton ID="radNo" runat="server" GroupName="test" Text="No"></asp:radiobutton> </div> <div> <asp:radiobutton ID="radDisabledYes" runat="server" GroupName="test2" Text="yes"></asp:radiobutton> <asp:radiobutton ID="radDisabledNo" runat="server" GroupName="test2" Text="No"></asp:radiobutton> </div> <asp:LinkButton ID="lnktoto" runat="server" Text="Submit"></asp:LinkButton> </form> </body> </html>
And the code behind:
Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then radDisabledYes.Enabled = radYes.Checked radDisabledNo.Enabled = radYes.Checked End If Stop End Sub Private Sub Radiobutton1_CheckedChanged(sender As Object, e As EventArgs) Handles radYes.CheckedChanged, radNo.CheckedChanged radDisabledYes.Enabled = radYes.Checked radDisabledNo.Enabled = radYes.Checked End Sub Private Sub lnktoto_Click(sender As Object, e As EventArgs) Handles lnktoto.Click Stop End Sub End Class
On the server side, disable the switches on first boot. I have the same conditions in javascript. Therefore, on the client side, if the user clicks Yes, I turn on some controls. I am doing the same thing on the server side. It works great with all types of controls except Radio Button.
Say that when I boot, I turn off the switches. On the client side, based on user input, I include them (in javascript). The user set the switch and sent the page. On the server side, the switch is disabled and not installed. I have a code that checks the conditions and activates it. But the switch is not yet set. I understand why the server ignores the checked state, because at first it considers that it is disconnected. Is there any way to make this work? I know that the server receives the checked state, because when I check Request.Form, I see radDisable = Yes.
Thank you for your help.
source share