【问题标题】:How to show error messages in the from of popup [duplicate]如何在弹出窗口中显示错误消息[重复]
【发布时间】:2020-08-26 23:47:39
【问题描述】:

我有一个疑问希望你们能解决,

我有两个文本框,一个是用户 ID,一个是表单中的用户名,我想以弹出窗口的形式显示错误消息如何在 ASP.NET 中执行

因为我是非常新的 ASP.net

谢谢

【问题讨论】:

  • 这个问题太笼统了,需要很多分类,因为你需要在帖子之后或之前显示消息,你使用任何javascript库吗? alert("message")confirm("are you sure?") 不好显示错误/消息?

标签: javascript html asp.net forms


【解决方案1】:

这是一个简单的例子,假设您只使用 javascript:

<form method='post' onsubmit="return validateForm();">
    <div class="form-group">
        <label class="col-4">User Id: </label>
        <input type="text" id="UserId" name='UserId' placeholder="User ID">
    </div>

    <div class="form-group">
        <label class="col-4">User Name: </label>
        <input type="text" id="UserName" name='UserName' placeholder="User Name">
    </div>

    <input type="submit" value="Submit">
</form>
@section scripts{
    <script>
        function validateForm()
        {
            if ($("#UserId").val() && $("#UserName").val()) {
                return true;
            }
            else {
                alert("Both User ID and User Name are required.")
            }
        }
    </script>
}

希望这将指导您进一步实施。

【讨论】:

    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    相关资源
    最近更新 更多