简体   繁体   English

如何在 ASP.NET 中使用类似于 WinForms 消息框的 Modal Pop Up 控件?

[英]How can I use a Modal Pop Up control in ASP.NET similar to a WinForms Message box?

I am building a form, where required field validation must have been checked.我正在构建一个表单,必须检查所需的字段验证。 I am not using asp validator.我没有使用 asp 验证器。 I am using JQuery validator like我正在使用 JQuery 验证器,例如

function checkRequiredInputs(){ 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.我在页面后面的代码中使用 c#。 Now if I turned off allowjavascript option in my browser, as far as I know it won't allow javascript.现在,如果我在浏览器中关闭 allowjavascript 选项,据我所知它不会允许 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.但是,由于 ASP.NET 没有消息框控件,我无法让用户知道他将哪个字段留空。 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?有什么方法可以使用消息框之类的控件来显示或让用户知道成功填写表单需要/需要哪些字段?

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

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.但是,如果您不想混淆两个 javascript 框架(ASP.NET AJAX 和 jQuery),则可以在此处过期,您可以在此处找到如何处理验证和 ZF590B4FDA2C30BE28DD3C8C3CAF5C7B7 的解决方案

If you want a modal popup, just send some javascript from the server code:如果你想要一个模式弹出窗口,只需从服务器代码发送一些 javascript :

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

alert() is a javascript function. alert()是 javascript function。 Response.Write() adds the <script> element to the end of the HTTP response (ie, the rendered HTML page). Response.Write()<script>元素添加到 HTTP 响应(即呈现的 HTML 页面)的末尾。

A more elegant approach would be to use the ClientScriptManager to register a startup script:更优雅的方法是使用 ClientScriptManager 注册启动脚本:

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.'); javascript 代码alert('A required field is missing.'); will be executed after the postback.将在回发后执行。

See also: http://www.4guysfromrolla.com/articles/021104-1.2.aspx另见: http://www.4guysfromrolla.com/articles/021104-1.2.aspx

Without javascript, I can't imagine a simple way of recreating a modal type popup.如果没有 javascript,我无法想象一种重新创建模态类型弹出窗口的简单方法。 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.您将不得不 go 回发并重新呈现页面,其中一个 DIV 阻止了页面,另一个 div 在其顶部出现错误。

You can always pipe out the errors to a tag next to the submit button and call it a day though.您总是可以 pipe 将错误发送到提交按钮旁边的标签中,然后收工。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM