简体   繁体   English

如何在ASP.NET中显示弹出消息框?

[英]How to show popup message box in ASP.NET?

Work on C# VS 2005 AJAX enabled web. 在启用C#VS 2005 AJAX的网站上工作。 I want to show a pop up message on my web page. 我想在网页上显示一条弹出消息。 In my desktop application I write the following code to show a message: 在我的桌面应用程序中,我编写了以下代码以显示消息:

MessageBox.Show("Data Saved Successfully.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);

I want this kind of message. 我想要这种信息。 Where i can set message icon, Message Header, Message text....I write a code for web : 我可以在其中设置消息图标,消息标题,消息文本...的地方。

s = "<script type=\"text/javascript\">alert('InCorrect DateFormat. Check Required.');</script>";
ClientScript.RegisterStartupScript(GetType(), "Alert", s);

Why it's not work ....And how to get message like desktop application. 为什么它不起作用...以及如何获取类似桌面应用程序的消息。

my button under the ajax update panel.After click data save but message is not show....if i put button out the update panel it's work show pop up message ....but i want button must stay on update panel 我的按钮在ajax更新面板下。单击数据保存后,但不显示消息....如果我将按钮放出更新面板,则它的工作将显示弹出消息....但是我希望按钮必须保留在更新面板上

Your second code-snippet works for me, it shows the message box when the page is loaded in the browser. 您的第二个代码段对我有用,当页面在浏览器中加载时,它会显示消息框。

Do you get any error message? 您收到任何错误消息吗? Can you show some more code? 您可以显示更多代码吗?

Regarding your second question: I don't think you can get the same message box as in the windows forms application (at least not with the standard javascript alert method). 关于您的第二个问题:我认为您无法获得与Windows窗体应用程序中相同的消息框(至少不能使用标准的JavaScript警报方法)。 If you really want to have an equal looking dialog (with icons), then you might have to search for some 3rd-party library (like jQuery (-UI), ExtJS , etc.). 如果您确实希望有一个外观相同的对话框(带有图标),那么您可能必须搜索一些第三方库(例如jQuery (-UI), ExtJS等)。

Update (regarding UpdatePanel): 更新(关于UpdatePanel):

According to this forum post , you should use ScriptManager.RegisterClientScriptBlock() instead of Page.ClientScript.RegisterClientScriptBlock(), but I think this is only available since .NET 3.5. 根据此论坛帖子 ,您应该使用ScriptManager.RegisterClientScriptBlock()而不是Page.ClientScript.RegisterClientScriptBlock(),但是我认为这仅适用于.NET 3.5。 For your case, you might want to try a workaround such as shown in this question . 对于您的情况,您可能想要尝试解决此问题中所示的方法。

Have you tried different browsers such as IE, FireFox, or Chrome. 您是否尝试过使用其他浏览器,例如IE,FireFox或Chrome。 Make sure that you don't have pop-up blocker? 确保您没有弹出窗口阻止程序?

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

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