如何在 ASP.NET 中使用类似于 WinForms 消息框的模态弹出控件?

发布于 2024-11-25 06:20:00 字数 668 浏览 0 评论 0 原文

我正在构建一个表单,必须检查所需的字段验证。我没有使用 asp 验证器。我正在使用 JQuery 验证器,例如

函数 checkRequiredInputs(){

$("#frmSaleSubmissionInfo").validate({  
    rules:{
        txtFName:{required: true},
        txtLName:{required: true},
        txtAddress:{required: true},
        txtPhone:{required: true}
    },
    messages:{
        txtFName:"Enter Name",
        txtLName:"Enter Name",
        txtAddress:"Enter Address",
        txtPhone:"Enter Phone Number"
    }
});

这是我的客户端验证。我在代码隐藏页面中使用 C#。现在,如果我关闭浏览器中的allowjavascript选项,据我所知它不会允许javascript。所以我也在对必填字段进行服务器端验证。但是,由于 ASP.NET 没有消息框控件,因此我很难让用户知道他将哪个字段保留为空。有没有办法使用消息框之类的控件来显示或让用户知道成功填写表单需要哪些字段?

I am building a form, where required field validation must have been checked. I am not using asp validator. I am using JQuery validator like

function checkRequiredInputs(){

$("#frmSaleSubmissionInfo").validate({  
    rules:{
        txtFName:{required: true},
        txtLName:{required: true},
        txtAddress:{required: true},
        txtPhone:{required: true}
    },
    messages:{
        txtFName:"Enter Name",
        txtLName:"Enter Name",
        txtAddress:"Enter Address",
        txtPhone:"Enter Phone Number"
    }
});

This is my client side validation. I am using c# in my code behind page. Now if I turned off allowjavascript option in my browser, as far as I know it won't allow javascript. So I am also doing server-side validation for required field. But, since ASP.NET does not have a message-box control, I am having trouble to let the user know what field he is keeping empty. Is there any way to use a control like the message box to show or let the user know what field(s) is/are required to fill the form successfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

友谊不毕业 2024-12-02 06:20:00

在我看来,最适合您的要求的是使用 ASP.NET AJAX Toolkit ValidatorCallout 控件,它可以帮助您更快地构建此类解决方案。

但是,如果您不想混合两个 javascript 框架(ASP.NET AJAX 和 jQuery),那么您可以 此处已过期,您可以在其中找到如何处理验证和 jQuery 的解决方案。

In my point of view, the best fitted to your requirement is using ASP.NET AJAX Toolkit ValidatorCallout control, which can help you to build such solution more fast way.

But if you don't want mixed up two javascript framework (ASP.NET AJAX and jQuery) than you can be expired here, where you can find a solution how to deal with a validation and jQuery.

树深时见影 2024-12-02 06:20:00

如果您想要模式弹出窗口,只需从服务器代码发送一些 javascript:

Response.Write(
    "<script type='text/javascript'>alert('A required field is missing.');</script>");

alert() 是一个 javascript 函数。 Response.Write()

更优雅的方法是使用 ClientScriptManager 注册启动脚本:

protected void Page_Load(object sender, EventArgs e) {
    this.ClientScript.RegisterClientScriptBlock(this.GetType(), 
        "RequiredFieldValidationScript", 
        "alert('A required field is missing.');", 
        true);
}

javascript 代码 alert('A required field ismissing.'); 将在回发后执行。

另请参阅:https://web.archive.org/web/20210417085026/https://www.4guysfromrolla.com/articles/021104-1.2.aspx

If you want a modal popup, just send some javascript from the server code:

Response.Write(
    "<script type='text/javascript'>alert('A required field is missing.');</script>");

alert() is a javascript function. Response.Write() adds the <script> element to the end of the HTTP response (i.e., the rendered HTML page).

A more elegant approach would be to use the ClientScriptManager to register a startup script:

protected void Page_Load(object sender, EventArgs e) {
    this.ClientScript.RegisterClientScriptBlock(this.GetType(), 
        "RequiredFieldValidationScript", 
        "alert('A required field is missing.');", 
        true);
}

The javascript code alert('A required field is missing.'); will be executed after the postback.

See also: https://web.archive.org/web/20210417085026/https://www.4guysfromrolla.com/articles/021104-1.2.aspx

花期渐远 2024-12-02 06:20:00

如果没有 javascript,我无法想象重新创建模式类型弹出窗口的简单方法。您必须回发并重新渲染页面,并使用一个 DIV 屏蔽该页面,并在其顶部放置另一个包含错误的 div。

您始终可以将错误输出到提交按钮旁边的标签,然后就到此为止了。

Without javascript, I can't imagine a simple way of recreating a modal type popup. You would have to go as to postback and re-render the page with a DIV blocking out the page and another div on top of it with the errors.

You can always pipe out the errors to a tag next to the submit button and call it a day though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文