【问题标题】:Validation disappears on autopostback验证在自动回发时消失
【发布时间】:2017-12-31 04:15:19
【问题描述】:

我正在使用 javascript 函数验证我的控件。我不能使用 asp 中可用的验证器。它工作正常,但是当单选按钮回发时,其余的验证就会消失。 这是我的验证码

 function ValidateForm() {
                var validate = true;                
         var summary = document.getElementById("<%=summary.ClientID%>");
                if (summary.value == "") {
                    summary.style.backgroundColor = "Yellow";
                    validate = false;
                }
                if (validate == false) {
                    alert('Please fill highlighted fields');
                }
                return validate;

这是验证的按钮代码

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" OnClientClick="return ValidateForm();" />

这是我的单选按钮代码

<asp:RadioButton ID="Submitter" Text="Submitter" GroupName="rd2" runat="server" ForeColor="Black" OnCheckedChanged="submitter_changed" AutoPostBack="true" />
                        <asp:RadioButton ID="Following" Text="Following" GroupName="rd2" runat="server" ForeColor="Black" OnCheckedChanged="following_changed" AutoPostBack="true" />

我希望颜色在 autopostback 之后不会改变。请帮我看看怎么做。

【问题讨论】:

  • 找到问题的解决方案了吗?
  • @Frost_Mourne 我正在编写 javascript 函数来启用和禁用选择字段,因此不需要自动回发
  • 当时好像整理好了..
  • 是的。但感谢您的帮助
  • 欢迎您。

标签: javascript asp.net validation


【解决方案1】:

尝试像这样使用 UpdatePanel

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:RadioButton ID="Submitter" Text="Submitter" GroupName="rd2" runat="server" ForeColor="Black" OnCheckedChanged="submitter_changed" AutoPostBack="true" />
        <asp:RadioButton ID="Following" Text="Following" GroupName="rd2" runat="server" ForeColor="Black" OnCheckedChanged="following_changed" AutoPostBack="true" />
   </ContentTemplate>
  </asp:UpdatePanel>

【讨论】:

  • 试过了。但同样的问题
  • UpdateMode=有条件的?
  • 它的工作。但 autopostback 不起作用。这阻止了我的工作
  • 发生自动回发时会发生什么?
  • 文本框启用和禁用
猜你喜欢
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多