How to select asp.net RadioButton with javascript when autopostback is on(启用自动回发时如何使用 javascript 选择 asp.net RadioButton)
问题描述
场景:
- 具有给定 GroupName 和
AutoPostBack="true" 的多个单选按钮.
- 出于样式目的,单选按钮使用 js 隐藏,对其容器(td)的点击通过 js 处理
- 当点击 td 时,脚本点击"输入元素并触发 asp.net 的自动回发
它在服务器上进行回发并点击 PageLoad,但未触发代码隐藏中的事件.
It does postback and hits PageLoad on the server, but the event in the codebehind is not triggered.
推荐答案
我发布这个以防万一有人不幸遇到这个问题.
I posted this in case anyone is unfortunate enough to hit this problem.
在对此答案的评论中非常准确地提到了问题https://stackoverflow.com/a/8244315/66372.
Problem is very accurately mentioned in a comment on this answer https://stackoverflow.com/a/8244315/66372.
但是 .click() 有一件事:如果您像这样使用 javascript 更改收音机的选定值,则更改"事件不会在 IE 中触发(我尝试过 IE8)– Michiel Reyers
There is however one thing with the .click(): If you change the selected value of a radio with javascript like this, the 'change' event does not fire in IE (I tried IE8) – Michiel Reyers
这似乎与 asp.net 的回发事件处理相混淆.所以为了让它捡起来,我们首先明确地选择它:
That seems to mess with asp.net's postback event handling. So for it to pick it up, we explicitly select it first:
$(this).find("input").prop("checked", true);
$(this).find("input").click();
这篇关于启用自动回发时如何使用 javascript 选择 asp.net RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:启用自动回发时如何使用 javascript 选择 asp.net RadioButton


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01