Click to See Complete Forum and Search --> : messageboxes with webapplication
Dozo_1st
Aug 22nd, 2002, 05:42 AM
Does anybody know how I can display messageboxes with a Webapplication? If I just use msgbox("etc",vb...) the webapplication halts and displays an error that it is not possible for webapplications to use user-interactive items.
But I've seen webpages which do display them. How can I use them?
Thanx.
Dozo
FatDaz
Aug 22nd, 2002, 07:14 AM
Because the web application is running on a server, the MsgBox function would not actually run on the Client's browser. The only way for a messagebox to appear on the client-side, is by using client-side scripting.
To add client-script dynamically, to run when the page is loaded you can use the "RegisterStartupScript"
e.g.
RegisterStartupScript("RaisePopup", "<script language=""VBSCRIPT"">Msgbox ""Hello""</script>")
When you use this, the message box does not appear immediately on the client's browser (so if you debug through the code, don't expect to see the msgbox appear immediately). It will appear after the page has been rendered on the server, and is loaded into the client's browser.
Dozo_1st
Aug 22nd, 2002, 08:07 AM
Just what I was looking for!
FatDaz
Aug 22nd, 2002, 08:15 AM
This command needs to go with your server-side code. When you use it, it will add the necessary code to the HTML that is displayed in the client's browser.
As a simple example, you could have the ASPX file containing...
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="SPWebSite.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
And your code-behind ASPX.VB file has...
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Private Sub ShowPopupMessage(ByVal Message As String)
RegisterStartupScript("RaisePopup", "<script language=""VBSCRIPT"">Msgbox """ & Message & """</script>")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowPopupMessage("Hello")
End Sub
End Class
So this is being run on the server, you can then use the ShowPopupMessage sub routine whenever you need to force the popup message to appear.
So you could use this method say if the user is posting information to your web site, but gives invalid information. The server checks the data after it is posted, and forces the msgbox to popup if a problem was found.
The alternative is to hard code into the HTML page, for example the web application above implemented on a pure HTML page would be (at least one of the ways)...
<html>
<body>
<INPUT id="Button1" type="button" value="Button" name="Button1">
<script language="vbscript">
Sub Button1_OnClick()
Msgbox "Hello"
End Sub
</script>
</body>
</html>
If anything still isn't clear, just let me know.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.