简体   繁体   English

单选按钮不更新服务器端的值

[英]Radio Button not updating value on Server Side

I have 3 radio buttons in a form which are all part of a single group. 我有3个单选按钮,它们都是一个组的一部分。 When one of the non-default radio buttons is clicked, they update on the client side properly (deselects previous radio button and selects new one). 单击一个非默认单选按钮时,它们会在客户端正确更新(取消选择上一个单选按钮并选择新的单选按钮)。 I have even attached an OnClientClick to the button that submits the form to test it and right before the form is submitted the .checked values are correct. 我什至将OnClientClick附加到提交表单以对其进行测试的按钮上,并且在提交表单之前.checked值正确。 But the first line of code that is reached on the server side checks the values, again for testing purposes, but .checked values have not changed. 但是,在服务器端到达的第一行代码再次检查这些值,以进行测试,但是.checked的值没有更改。 The default is still checked according to the server. 仍根据服务器检查默认值。

Here is some of my relevant code: 这是我的一些相关代码:

ASP 均价

<asp:RadioButton runat="server" ID="rdoDays" Text=" Days" GroupName="RepeatType" />
<asp:RadioButton runat="server" ID="rdoMonths" Text=" Months" GroupName="RepeatType" />
<asp:RadioButton runat="server" ID="rdoYears" Text=" Years" GroupName="RepeatType" />

<asp:Button runat="server" ID="btnSaveAlert" OnClick="btnSaveAlert_OnClick" 
     Text="Save" OnClientClick="Test()" />

Javascript - when month is clicked, the javascript shows "False" then "True" for the alert boxes as it should. Javascript-单击月份时,JavaScript会在警报框中显示“ False”,然后显示“ True”。

function Test() {
    var rdoDays = document.getElementById("<%= rdoDays.ClientID %>");
    var rdoMonths = document.getElementById("<%= rdoMonths.ClientID %>");
    var rdoYears = document.getElementById("<%= rdoYears.ClientID %>");
    alert(rdoDays.checked);
    alert(rdoMonths.checked);
}

Then for the C#, I have set a breakpoint in VS at the very beginning of Page_Init and the radio button .checked values are all "false" 然后对于C#,我在Page_Init的最开始处设置了VS中的断点,并且单选按钮.checked值都是“ false”

I have no idea what's going on. 我不知道发生了什么事。 Am I missing a tag in the asp element or something? 我在asp元素中缺少标签吗? Any help is greatly appreciated. 任何帮助是极大的赞赏。

Viewstate is loaded in between OnInit and OnLoad. Viewstate加载在OnInit和OnLoad之间。 Try checking to see if the radio button is checked in the OnLoad event of the page. 尝试检查页面的OnLoad事件中是否选中了单选按钮。

Perhaps you could use Fiddler to test to see what data is being sent from your client to your server to try to narrow down where the actual problem is: 也许您可以使用Fiddler进行测试,以查看从客户端向服务器发送的数据,以缩小实际问题的范围:

http://www.fiddler2.com/fiddler2/ http://www.fiddler2.com/fiddler2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM