如何在asp.net中显示msgbox? [英] How to display msgbox in asp.net?
本文介绍了如何在asp.net中显示msgbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#在asp.net中显示msgbox?
我无法使用windows.msgbox
它可以通过,
Response.Write(< script> alert(''Item Already Exists'')< / script>);
但我面临的问题是,当显示msgbox时,实际网页变为空白(即全白),点击确定后,我又回到了页面。有没有办法同时显示msgbox和页面?
解决方案
试试:
ClientScript.RegisterStartupScript(this.GetType(),myalert,alert(''+ myStringVariable +'');,true);
你无法执行Response.Write,因为它会清除内容并将响应作为你在Write方法中发送的内容。
相反,假设您在asp.net页面中有一个按钮,并且单击要从C#显示消息框的按钮,然后,您可以执行此操作o n C中的按钮点击事件#
string javaScript = alert('Item Already Exists');;
Page.ClientScript.RegisterStartupScript( this .GetType(), ButtonClickEventScript,javaScript, true );
http://forums.asp.net/t/1461308.aspx/1 [ ^ ]
http://www.c-sharpcorner.com/UploadFile/mahesh/WebMsgBox09082006110929AM/WebMsgBox。 aspx [ ^ ]
How to display a msgbox in asp.net using C#?
I can''t do it using windows.msgbox
It can be done by,
Response.Write("<script>alert(''Item Already Exists'')</script>");
But the problem I am facing is that, when the msgbox is being displayed, the actual webpage turns blank (i.e. full white), and on clicking OK, I am getting back the page again. Is there any way to display the msgbox as well as the page at the same time?
解决方案
Well try with:
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert(''" + myStringVariable + "'');", true);
Also check this article:
Simple MessageBox functionality in ASP.NET[^]
Cheers
You cant do Response.Write since it wipes out the content and put the response as what you are sending inside the Write method.
Instead lets say you have a button in your asp.net page and on click of the button you want to show the message box from C# then,You can do this on the button click event in C#
string javaScript = "alert('Item Already Exists');"; Page.ClientScript.RegisterStartupScript(this.GetType(),"ButtonClickEventScript", javaScript,true);
http://forums.asp.net/t/1461308.aspx/1[^]
http://www.c-sharpcorner.com/UploadFile/mahesh/WebMsgBox09082006110929AM/WebMsgBox.aspx[^]
这篇关于如何在asp.net中显示msgbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文