如何检查回发后形式 [英] how to check form after postback

查看:102
本文介绍了如何检查回发后形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请cosider这样的场景:

我有3下拉list.I地方形式的更新面板这些控件。当我的用户首降选择具有值大于2的项目下来名单我禁用第二个和第三个下拉使用jQuery列表。我的问题是之后的任何回发的所有下拉列表中enable.I知道这是正常的,但我怎么能再次检查的形式和禁用,应该是禁用的控制?

感谢

修改1)

这是我的code:

 < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>
        <&的ContentTemplate GT;
            <表边框=1的cellpadding =0CELLSPACING =0>
                &所述; TR>
                    &所述; TD>
                        < ASP:DropDownList的ID =DropDownList1=服务器WIDTH =100px的>
                            &所述; asp的:列表项值=1的文本=1/>
                            < ASP:ListItem的值=2文本=2/>
                            < ASP:ListItem的值=3文本=3/>
                        < / ASP:DropDownList的>
                    < / TD>
                < / TR>
                &所述; TR>
                    &所述; TD>
                        < ASP:DropDownList的ID =DropDownList2=服务器WIDTH =100px的>
                            &所述; asp的:列表项值=1的文本=1/>
                            < ASP:ListItem的值=2文本=2/>
                            < ASP:ListItem的值=3文本=3/>
                        < / ASP:DropDownList的>
                    < / TD>
                < / TR>
                &所述; TR>
                    &所述; TD>
                        < ASP:DropDownList的ID =DropDownList3=服务器WIDTH =100px的>
                            &所述; asp的:列表项值=1的文本=1/>
                            < ASP:ListItem的值=2文本=2/>
                            < ASP:ListItem的值=3文本=3/>
                        < / ASP:DropDownList的>
                        < BR />
                    < / TD>
                < / TR>
            < /表>
            < D​​IV>
                < ASP:按钮的ID =Button1的=服务器文本=原因后返回WIDTH =200像素
                    的onclick =的button1_Click/>
            < / DIV>
        < /&的ContentTemplate GT;
    < / ASP:的UpdatePanel>

和JavaScript的:

  $(文件)。就绪(函数(){
        功能禁用(项目){
            item.attr('残疾','禁用');
        }
        $('#DropDownList1)。改变(函数(){
            如果($(本).VAL()→2){
                禁用($('#DropDownList2'));
                禁用($('#DropDownList3'));
            }
            其他{
                启用($('#DropDownList2'));
                启用($('#DropDownList3'));
            }
        })。更改();        功能启用(项目){
            item.removeAttr('禁用');
        }
    });


解决方案

我缺少的东西吗?

  $('#dropdown1')。改变(函数()
{
    如果($(本).VAL()→2)
    {
        $('#dropdown2,#dropdown3')丙(禁用,真正的);
    }
    其他
    {
        $('#dropdown2,#dropdown3')丙(禁用,假);
    }
})
。更改();

Please cosider this scenario:

I have a form with 3 drop down list.I place these controls in an update panel.when my users select an Item with value greater that 2 in first drop down list I disable second and third drop down list with jQuery. My problem is after any post back all drop down list are enable.I know this is normal but how I can check the form again and disable controls that should be disable?

thanks

Edit 1)

this is my code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <table border="1" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server" Width="100px">
                            <asp:ListItem Value="1" Text="1" />
                            <asp:ListItem Value="2" Text="2" />
                            <asp:ListItem Value="3" Text="3" />
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DropDownList ID="DropDownList2" runat="server" Width="100px">
                            <asp:ListItem Value="1" Text="1" />
                            <asp:ListItem Value="2" Text="2" />
                            <asp:ListItem Value="3" Text="3" />
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DropDownList ID="DropDownList3" runat="server" Width="100px">
                            <asp:ListItem Value="1" Text="1" />
                            <asp:ListItem Value="2" Text="2" />
                            <asp:ListItem Value="3" Text="3" />
                        </asp:DropDownList>
                        <br />
                    </td>
                </tr>
            </table>
            <div>
                <asp:Button ID="Button1" runat="server" Text="Cause Post Back" Width="200px" 
                    onclick="Button1_Click"/>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

and javascript:

 $(document).ready(function () {
        function Disable(item) {
            item.attr('disabled', 'disabled');
        }
        $('#DropDownList1').change(function () {
            if ($(this).val() > 2) {
                Disable($('#DropDownList2'));
                Disable($('#DropDownList3'));
            }
            else {
                Enable($('#DropDownList2'));
                Enable($('#DropDownList3'));
            }
        }).change();

        function Enable(item) {
            item.removeAttr('disabled');
        }
    });

解决方案

Am I missing something?

$('#dropdown1').change(function()
{
    if ( $(this).val() > 2 )
    {
        $('#dropdown2, #dropdown3').prop('disabled', true);
    }
    else
    {
        $('#dropdown2, #dropdown3').prop('disabled', false);
    }
})
.change();

这篇关于如何检查回发后形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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