且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#在ASP.NET中显示消息框

更新时间:2023-12-06 07:49:57

在Windows应用程序中,您可以使用:



MessageBox.Show(您的消息);



在Web应用程序中,您可以使用服务器端代码中的java脚本

Page.ClientScript.RegisterStartupScript(this.GetType(),scriptkey,alert) ('您的消息'););
In windows Application you can use :

MessageBox.Show("your message");

In web Applications you can use java script from server side code
Page.ClientScript.RegisterStartupScript(this.GetType(),"scriptkey","alert('your message');");


在您的页面中添加脚本代码:

add script code in your page:
<script type="text/javascript">
        function Showalert() {
            alert('Call JavaScript function from codebehind');
        }
</script>

here is code for display the alert message... It is similar to msgbox.

<pre>
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Show alert" onclick="btnSubmit_Click"/>
<asp:Button ID="btnClick" runat="server" Text="Call JavaScript Function" onclick="btnClick_Click" />
</div>





我希望这对你有帮助。



I hope this is help for You.


您可以添加System.Window.Form的引用,这将在您的asp.net应用程序中添加MessageBox,当您处于调试模式时,这是好的,只是您想要测试您的网站。但是当你主持你的网站时,问题就出现了,这意味着生产阶段。

你的javascript更好。
You can add reference of System.Window.Form, that would give to add MessageBox in your asp.net application, it is good when you are in debug mode mean only you want to test your website. But problems come when you host you host your website, mean production phase.
Better you you javascript.