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

1

本文介绍了在回发时保留单选/复选框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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.

http://www.4guysfromrolla.com/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();
}

这篇关于在回发时保留单选/复选框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14