ASP.NET没有看到单选按钮值的变化 [英] ASP.NET not seeing Radio Button value change
问题描述
我有被默认禁用某些单选按钮的形式。
I have a form with some radio buttons that are disabled by default.
当值被输入到一个文本框,单选按钮通过启用JavaScript。然后,用户选择一个单选按钮,并点击提交按钮哪些职位回服务器。
When a value gets entered into a text box, the radio buttons are enabled via javascript. The user then selects one of the radio buttons and clicks on a submit button which posts back to the server.
当我回到服务器,即作为托运用户点击未显示的单选按钮。我会用'rbSolid作为单选按钮,我重点关注。
When I get back to the server, the radio button that user clicked is not showing as checked. I'll use 'rbSolid' as the radio button I'm focusing on.
我处理单选按钮的onclick事件,但我不具备的功能做任何事情比其他射击:
I handle the 'onclick' event of the radio buttons, but I don't have the function doing anything yet other than firing:
Me.rbSolid.Attributes.Add(onclick事件,styleLookupChanged(本);)
Me.rbSolid.Attributes.Add("onclick", "styleLookupChanged(this);")
在客户端,这使得当文本框的值被改变的单选按钮:
On the client, this enables the radio button when the textbox value is changed:
的document.getElementById(ctl00_MainLayoutContent_WebPanel4_rbSolid)禁用= FALSE;
document.getElementById("ctl00_MainLayoutContent_WebPanel4_rbSolid").disabled = false;
我然后点击单选按钮,然后通过一个按钮后回来,但后面的服务器上,这是始终为false:
I then click the radio button then post back via a button, but back on the server this is always false:
如果Me.rbSolid.Checked则...
If Me.rbSolid.Checked Then...
如果我有默认启用的单选按钮,它显示为正常检查。
If I have the radio button enabled by default, it shows as checked correctly.
感谢您的帮助!
推荐答案
这与如何ASP.NET回发数据做。如果控制被禁用时,页面呈现比的值将不会发布回服务器(control.enabled = FALSE)。如何我在过去已经解决了它使用属性标签,而不是使用Enabled属性设置禁用标志。因此,而不是control.enabled =假的,你用control.attributes.add(禁用,禁用)。
This has to do with how ASP.NET postback data. If a control is disabled (control.enabled = false) when the page is rendered than the values will not be posted back to the server. How I have solved it in the past is to set the disabled flag using attributes tags instead of using the Enabled property. So instead of control.enabled = false, you use control.attributes.add("disabled", "disabled").
这篇关于ASP.NET没有看到单选按钮值的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!