简体   繁体   English

asp.net Web应用程序中的消息框

[英]message box in asp.net web application

how to display the 'successfully saved' message box in asp.net web application by using javascript. 如何使用javascript在asp.net Web应用程序中显示“成功保存”消息框。

any idea ??? 任何想法 ???

Option 1 选项1

You can put arbitrary content on the page at just about any location by simply creating and appending absolutely-positioned DOM elements, see this question's answer for details, but fundamentally: 您可以通过简单地创建并附加绝对放置的DOM元素,将任意内容放置在页面上的几乎任何位置,有关详细信息,请参见此问题的答案 ,但从根本上讲:

var element;

element = document.createElement('div'); // Or whatever
element.style.position = "absolute";
element.style.left = "100px";
element.style.top = "100px";
element.style.width = "200px";
element.style.height = "200px";

document.body.appendChild(element);

The left , top , etc. can be any valid CSS values. lefttop等可以是任何有效的CSS值。 You may also want to use z-index to ensure it appears on top of other content. 您可能还需要使用z-index来确保它出现在其他内容的顶部。

Of course, when they click on it or something you'll want to remove it: 当然,当他们单击它或您想要将其删除时:

document.removeChild(element);

If you want to "grey-out" the underlying page and such, you can use an iframe shim to achieve that. 如果要“灰显”基础页面等,可以使用iframe填充程序来实现。

Option 2 选项2

Another alternative is to use the JavaScript alert function, but it's pretty intrusive and old-fashioned looking. 另一种选择是使用JavaScript alert功能,但是它看起来非常具有侵入性和老式气息。

alert ( "Successfully saved" );

Display an alert dialog with the specified content and an OK button. 显示带有指定内容和“确定”按钮的警报对话框。 See window.alert 参见window.alert

The problem with an alert box is that it blocks the user from any further action. 警报框的问题在于它阻止用户执行任何进一步的操作。 Better if you can show custom messages in containers like <span> or <div> and place them in the page. 如果可以在<span><div>类的容器中显示自定义消息并将其放置在页面中,则更好。

Edit 编辑

If you can use jQuery then this one has diferent sets of custom alert boxes. 如果您可以使用jQuery,则此版本具有不同的自定义警报框集。

jQuery impromptu jQuery即兴

Response.write("<script>alert('Successfully saved !');</script>"); Response.write(“ <script> alert('成功保存!'); </ script>”));

or call a javascript function which takes parameter Response.write("<script>ShowMessage('Successfully saved !');</script>"); 或调用带有参数Response.write(“ <script> ShowMessage('Successfully saved!'); </ script>”)的javascript函数;

//client side function //客户端功能

function ShowMessage(message) { alert(message); 函数ShowMessage(message){alert(message); } }

Instead of registering a some JavaScript code like this: 而不是像这样注册一些JavaScript代码:

Response.write("<script>ShowMessage('Successfully saved !');</script>");

it is a bit cleaner to use this built-in method: 使用此内置方法比较干净:

Page.ClientScript.RegisterStartupScript(this.GetType(), "showMyMessage", "ShowMessage('Successfully saved!');", true);

This is a bit cleaner than using Response.Write and it automatically prepends and appends your code with '<script type="text/javascript">' and '</script>'. 这比使用Response.Write干净一点,它会自动在代码之前加上'<script type =“ text / javascript”>'和'</ script>'。

In your ShowMessage(MyMessage) function you could do a simple alert() or you could do something like TJ Crowder suggests. 在ShowMessage(MyMessage)函数中,您可以执行简单的alert()或执行TJ Crowder建议的操作。

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

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