如何在没有回发的情况下访问复选框的值?
我有一个 radgrid 控制用户对应用程序的访问。有两列,“名称”列和代表当前访问权限的复选框“访问”列。复选框是从数据库填充的。我想更改复选框以授予或拒绝我指定的用户的访问权限。由于有很多用户,我想进行多项更改并使用提交按钮将更改写入数据库。我不想回发每个复选框更改并等待页面“闪烁”。我的问题是,在禁用复选框回发的情况下,当我单击提交时,复选框的值不会注册我所做的更改。我需要一种方法来访问复选框的当前客户端状态或一些解决方法来完成此操作。
提前致谢!
I have a radgrid controlling access to an application for users. There are two columns, a 'name' column and a checkbox 'access' column representing their current access permission. the checkboxes are populated from a database. I would like the to change the checkboxes to grant or deny access to the users I specify. Since there are alot of users I would like to make multiple changes and use a submit button to write the changes to the database. I do not want to postback with each checkbox change and wait for the page to "blink". My problem is that with the checkbox postback disabled, when I click submit, the value of the checkboxes are not registering the changes I make. I need a way to access the current client-side state of the checkbox or some workaround to accomplish this.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不知道为什么您无法访问服务器端复选框的值,但要回答您的问题“我需要一种方法来访问复选框的当前客户端状态或一些解决方法来完成此操作”...
您可以使用服务器标签并读取客户端复选框的值。
有关服务器标记的详细信息,请阅读此 MSDN 链接。
Not sure why you are not able to access the values of checkbox at server side, but to answer your question "I need a way to access the current client-side state of the checkbox or some workaround to accomplish this"...
You can use server tags and read the values of checkboxes at client side.
For more information about server tags, read this MSDN link.
如果将 AutoPostBack 设置为 false,则会禁用回发,但它们仍应发布其当前值。
在我看来,这更像是动态生成复选框的问题。
If you set AutoPostBack to false, that will disable the postback, but they should still be posting their current values.
Sounds to me more like an issue with the dynamic generation of the checkboxes.
感谢您的支持。事实证明,问题不在于客户端/服务器端可见性,而在于页面生命周期。我正在 PageLoad 方法中刷新 radgrid,并检查 Submit 方法中复选框的值。我没有意识到 PageLoad 是在提交之前执行的,因此清除了我的选择。通过从 PageLoad 中删除 RadGrid 刷新,复选框的当前值得以保留。
Thank you for the support. It turns out that the issue wasnt with client/server-side visibility, but with the page lifecycle. I was refreshing the radgrid in the PageLoad method and checking the value of the checkboxes in the Submit method. I didn't realize PageLoad was executed prior to Submit, thus clearing my selections. By removing the RadGrid refresh from PageLoad, the current values of the checkboxs were preserved.
您可以使用 javascript 发送 ajax 请求,将更改保存到数据库,而无需重新加载页面。然后您的更新就会立即发生,没有“眨眼”。
You could use javascript to send an ajax request that saves the change to the database without reloading the page. Then your updates happen right away and there's no "blink".