【问题标题】:Onclick of submit button are not displayed values of labelsOnclick 提交按钮不显示标签值
【发布时间】:2016-07-27 23:20:12
【问题描述】:

我有 2 个文本框 1 个按钮和 2 个标签,单击时,textbox1 的按钮值不会显示在 label3 上,textbox2 的值不会显示在 label2 我正在使用Verify.js 来验证文本框。 这是我的源代码:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
    <script src="http://rawgit.com/jpillora/verifyjs/gh-pages/dist/verify.notify.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" data-validate="required" runat="server"></asp:TextBox><br/>
        <asp:TextBox ID="TextBox2" data-validate="required" runat="server"></asp:TextBox><br/>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
        <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
    </form>
</body>
</html>

后面的代码:

protected void Button1_Click(object sender, EventArgs e)
{
  Label3.Text = TextBox1.Text;
  Label2.Text = TextBox2.Text;
}

谢谢大家!

【问题讨论】:

  • 你的代码有没有被命中?或者如果 TextBox1.Text 有任何值,你可以调试你的代码吗?
  • 这不应该是 OnClientClick 属性而不是 OnClick 属性吗?如图on the MS site
  • @user1490835 Button1_Click 方法中的代码未执行
  • 可能是 verify.js 有问题。尝试将您的按钮更改为

标签: c# jquery asp.net jquery-plugins


【解决方案1】:

这是 verify.js 的问题 link

尝试另一个验证,例如引导程序bootstrap validation,表单验证form validation

【讨论】:

    【解决方案2】:

    我试过这个,我发现由于 verify.js 引起的某种原因它没有命中服务器代码。 所以尝试使用客户端代码设置两个标签值。

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="test()"/>
    
    <script type="text/javascript">
        function test() {
           document.getElementById("<%=Label2.ClientID%>").innerText = document.getElementById("<%=TextBox1.ClientID%>").value;
           //Somthing like this
        }
    </script>
    

    希望这会有所帮助..

    【讨论】:

      猜你喜欢
      • 2016-02-20
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 2017-12-31
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      相关资源
      最近更新 更多