asp.net中的自动回传属性 [英] Autopostback properties in asp.net

查看:60
本文介绍了asp.net中的自动回传属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有2个单选按钮组;
选中单选按钮时会触发事件.

选中第一个单选按钮组按钮没有问题;按照单选按钮生成一个下拉列表.
当我单击第二个单选按钮组服务器时,忘记了第一个单选按钮组的值,并且未选中单选按钮组.
这是代码:

* .aspx:

There is 2 radio button group in my website;
An event is fired when the radio button is checked.

There is no problem when the 1st radio button group button is checked; a dropdown is generated as per the radio button cheched.
When i am clicking on the second radio button group server forgot 1st radio button group value and radion button group is unchecked.
Here is the code:

*.aspx:

<asp:RadioButton ID="pickupfrom1" runat="server" Text="Yes" GroupName="pickupfrom"oncheckedchanged="pickupfrom1_CheckedChanged" AutoPostBack="True" />
<asp:RadioButton ID="pickupfrom2" runat="server" Text="No" Checked="true" 
                                    GroupName="pickupfrom" oncheckedchanged="pickupfrom2_CheckedChanged" 
                                    AutoPostBack="True" />





<asp:DropDownList ID="pickupfrom" runat="server" Visible="false"

                                    AutoPostBack="True">
                            <asp:ListItem>Airport</asp:ListItem>


</asp:DropDownList>


第二个单选按钮组:


Second Radio button group:

<asp:RadioButton ID="dropto1" runat="server" Text="Yes" GroupName="dropto"
                                        oncheckedchanged="dropto1_CheckedChanged" AutoPostBack="True" />
                            <asp:RadioButton ID="dropto2" runat="server" Text="No" Checked="true"
                                        GroupName="dropto" oncheckedchanged="dropto2_CheckedChanged"
                                        AutoPostBack="True" />


<asp:DropDownList ID="dropto" runat="server" Visible="false" AutoPostBack="True">
                            <asp:ListItem>Airport</asp:ListItem>


</asp:DropDownList>



* .cs



*.cs

protected void pickupfrom1_CheckedChanged(object sender, EventArgs e)
    {
         pickupfrom.Visible = true;

    }
    protected void pickupfrom2_CheckedChanged(object sender, EventArgs e)
    {
         pickupfrom.Visible = false;

    }
    protected void dropto1_CheckedChanged(object sender, EventArgs e)
    {
        dropto.Visible = true;

    }
    protected void dropto2_CheckedChanged(object sender, EventArgs e)
    {
        dropto.Visible = false;

    }



选中单选按钮时,页面已加载,然后页面显示未选中单选按钮.
这就是为什么我无法获得价值.
任何人都可以帮助解决这个问题.

在此先谢谢您.



When radio buttons are checked page is loaded and then page displays no radio button is checked.
that''s why i cant get the value.
Can any one please help to solve this issue.

Thanks in advance.

推荐答案

您可以保留的值,也可以保留复选框是否为info的状态.在任何隐藏字段变量和页面加载中,请检查它们是否相同或从hiddenfield检索值.
You can keep the values of or weather the checkbox is checked or not info. in any hidden field variable and on page load check the same or retrive the values from the hiddenfield.


请勿使用自动回发.您要做的只是在回发期间设置控件的可见性.这可以通过简单的JavaScript代码完成,而无需耗时的页面刷新
Don''t use autopostback. All you are doing is setting visibilty of a control during the post back. This can be done with a simple line of JavaScript and not require the time consuming page refresh


这篇关于asp.net中的自动回传属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆