Cannot display message box on dev server in asp.net
I have a code block that is supposed to display a windows style message box to the user in my asp.net application.
The user performs an action on an asp.net page, that page then processes data on another aspx page. The second aspx page is where the message box code is to be displayed.
The box is displayed on my local machine, and another developers local machine. But the dev server does not display it. Nothing in the error log either.
Code
Page1.aspx
Dim strString As String = SysUtility.CheckRecord(Session("UserID"), sPageType)
If Mid(strString, 1, 6) = "ERROR:" Then MsgBox(strString, MsgBoxStyle.Critical)
Page2.aspx
function CheckRecord(strPage)
.....
.... database check to see if record is valid
....
.... if invalid, return "Error: Invalid record"
....
end function
How can I resolve this issue (need to display the message box when app is migrated to the dev server)开发者_开发知识库
MsgBox is for WinForms. In ASP.NET, you have the Javascript alert
and confirm
dialogs, and the jQuery UI Dialog. You can also use the ModalPopupExtender
included in the AJAX Toolkit. There are other solutions too, but those are the most common.
The simplest solution would be to show an alert, and you can do that like this:
Page.ClientScript.RegisterStartupScript(GetType(), "ShowMessageScript", "alert('Hello World!');", true);
You cannot execute win 32 api calls on a client computer from code running in your IIS web server!
Setup a system where alert style messages are rendered down to the page in an onload javascript alert type message, or maybe a jquery growl style plugin.
You won't be able to use MsgBox as that is a windows forms thing. There are several ways you could display a similar sort of thing in asp.net.
If it's just for tracing purposes (you mention "dev server") then a simple;
Response.write("Computer says no");
would work. If you need it to be nice and styled for the user, you could put a protected string in your code behind...
protected string _errorMessage = "";
assign whatever value you want to it on your page load, then a nugget on the page itself;
<%= _errorMessage %>
you could place wherever you want, and use a combination of html elements and a placeholder to mark it up however you like.
The final alternative would be to squirt some javascript on to your page which uses the "alert" method, which would look almost exactly like a windows forms popup, but generally they are not good practice in web design.
This cannot be done in the way that you want it to be done. If you plan to execute something like MsgBox
or MessageBox.Show
in your server's code behind you will be out of luck. The reason you cannot do this is because a modal popup box would appear on the server and would block the process until someone somewhere on that server clicks OK or Cancel, or whatever button. What you need is to do this on the client side by calling javascript alert()
function.
精彩评论