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


- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01