提交按钮的单击不显示标签的值

时间:2016-04-07 07:56:56

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

我有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;
}

感谢所有人!

2 个答案:

答案 0 :(得分:1)

这是verify.js的问题 link

尝试使用另一个验证,例如bootstrap bootstrap validation,表单验证form validation

答案 1 :(得分:0)

我试过这个,我发现由于某些原因,它不会因验证而导致验证服务器代码。 所以尝试使用客户端代码设置两个标签值。

private void handleGetTimeDate(User_Itf user, HttpServletRequest request, HttpServletResponse response) throws IOException, ServiceException {
  JSONObject time = new JSONObject();

  ZonedDateTime now = ZonedDateTime.now();
  time.put("hour", now.getHour());
  time.put("minute", now.getMinute());
  time.put("second", now.getSecond());
  time.put("year", now.getYear());
  time.put("month", now.getMonthValue());
  time.put("day", now.getDayOfMonth());
  time.put("zone", now.getZone());

  response.getWriter().print(time);
  response.setStatus(HttpServletResponse.SC_OK);
}

希望这会有所帮助..