2

我有这个UpdatePanel

<asp:TextBox ID="date" runat="server" />

<asp:ScriptManager ID="Manager" runat="server" />
            <asp:UpdatePanel ID="setDate" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
                <ContentTemplate>
                       <asp:Label ID="checkRes" runat="server" />&nbsp;<asp:Label ID="range" runat="server" />

                        <asp:ImageButton ID="check" runat="server" ImageUrl="../img/process.png" OnClick="check_Click" CausesValidation="false" UseSubmitBehavior="false"/>

                        <asp:Button ID="submit" runat="server" Text="Submit" CausesValidation="true" Enabled="false" />

                    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="setDate">
                        <ProgressTemplate>

                            <asp:Image ID="loader" runat="server" ImageUrl="~/img/loader.gif" />
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </ContentTemplate>

                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="check" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
<script type="text/javascript">
    var textBox = document.getElementById('<% =date.ClientID %>');
    var submitButton = document.getElementById('<% =submit.ClientID %>');
        textBox.onchange = function () {
            submitButton.disabled = true;
        };
</script>

后面有这段代码:

 protected void check_Click(object sender, EventArgs e)
   {
      submit.Enabled=true;
   }

可以看到先Button禁用,UpdatePanel触发后会启用;现在我想要 if date's text changedButton变为禁用。我在这里测试了我的 JS,但它没有Button在 ASPX 中禁用。

4

1 回答 1

1

回发后,清除与控件的绑定。这就是原因。

尝试这个,

<asp:TextBox ID="date" runat="server" />
    <asp:ScriptManager ID="Manager" runat="server" />
    <script type="text/javascript">
        function pageLoaded()
        {
            var textBox = document.getElementById( '<% =date.ClientID %>' );
            var submitButton = document.getElementById( '<% =submit.ClientID %>' );
            textBox.onchange = function ()
            {
                submitButton.disabled = true;
            };
        }


        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded( pageLoaded );
    </script>
    <asp:UpdatePanel ID="setDate" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            &nbsp;<asp:Label ID="checkRes" runat="server" />&nbsp;<asp:Label ID="range" runat="server" /><br />
            <asp:ImageButton ID="check" runat="server" ImageUrl="http://static.adzerk.net/Advertisers/d18eea9d28f3490b8dcbfa9e38f8336e.jpg"
                OnClick="check_Click" CausesValidation="false" UseSubmitBehavior="false" />
            <br />
            <asp:Button ID="submit" runat="server" Text="Submit" CausesValidation="true" Enabled="false" />

            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="setDate">
                <ProgressTemplate>
                    <asp:Image ID="loader" runat="server" ImageUrl="~/img/loader.gif" />
                </ProgressTemplate>
            </asp:UpdateProgress>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="check" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

您可以更改它,但脚本块必须放在脚本管理器之后。

于 2013-08-17T16:51:25.173 回答