在回发时保留单选/复选框值?

编程入门 行业动态 更新时间:2024-10-26 22:17:38
本文介绍了在回发时保留单选/复选框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

ASP 对象有一些我没有得到的东西.我在更新面板中有一个按钮.在同一页面上,我有一个复选框、一个单选按钮和一个文本框(在更新面板之外).当我点击我的按钮时,我可以访问所有这三个对象.文本框能够保留他的文本值.但是当我检查检查状态时,单选/复选框总是返回 false.

There's is something I don't get with ASP objects. I have a button in a update panel. On the same page, I have a checkbox, a radiobutton and a textbox (outside the update panel). When I click on my button, I access all those three objects. The textbox is able to keep the his text value. But the radio/checkbox always return false when I check there checked state.

当然,我的表格比我刚才说的要复杂.它涉及 Javascript 和用户控件.我设法使用 Request.Form 来获取我的复选框/收音机的值,但我觉得这个解决方案不够简洁.

Of course, my form is more complicated than what I just said. It involves Javascript and usercontrols. I managed to use the Request.Form to get the value of my checkbox/radio, but I don't find this solution to be neat enought.

有人可以帮我找出为什么收音机/支票不会返回真正的支票状态吗?提前谢谢!

Someone can help me to find why radio/check wont return there real checked state ? Thank you in advance!

我尝试在一个简单的 aspx 页面中进行跟踪,它似乎有效:

Edit : I've tried to following in a simple aspx page and it seems to works :

<asp:CheckBox runat="server" ID="checkbox" /> <asp:RadioButton runat="server" ID="radio1" GroupName="radio" CssClass="testRadio" /> <asp:RadioButton runat="server" ID="radio2" GroupName="radio" CssClass="testRadio" /> <asp:TextBox runat="server" ID="text" /> <asp:ScriptManager runat="server"> </asp:ScriptManager> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:Button runat="server" ID="test_but" OnClick="test_click" /> </ContentTemplate> </asp:UpdatePanel>

然后我可以访问 test_click() 中的所有属性.所以在我的真实形态中有些东西打破了其他一切.我尝试在我的测试页面中添加一些 javascript,它似乎也可以工作.

And then I can access all the properties into test_click(). So there is something in my real forms that breaks everything else. I've tried to add a little javascript into my test page, and it seems to works too.

推荐答案

这些控件的已知问题.使用 SaveViewState 和 LoadViewState 方法来存储和检索这些值.

Known issue with these controls. Use the SaveViewState and LoadViewState methods to store and retrieve these values.

www.4guysfromrolla/articles/110205-1.aspx

protected override void LoadViewState(object savedState) { base.LoadViewState(savedState); if (ViewState["Checked"] != null) checked = (bool)ViewState["Checked"]; } protected override object SaveViewState() { ViewState["Checked"] = checked; return base.SaveViewState(); }

更多推荐

在回发时保留单选/复选框值?

本文发布于:2023-10-12 21:13:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单选   复选框   回发时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!