MsgBox

  • Thread starter Thread starter Jim in Arizona
  • Start date Start date
J

Jim in Arizona

I wanted to make a pop up box to verify a choice to delete a database
record, so I tried this code:

Dim Result As MsgBoxResult
Result = MsgBox("Are You Sure?", MsgBoxStyle.OkCancel, "Sure?")
If Result = MsgBoxResult.Ok Then
Else
End If

The error I got was:

Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation. Specify the
ServiceNotification or DefaultDesktopOnly style to display a
notification from a service application.

I dont understand this message. How would I make a message box like this
work? I figured doing the code may render some kind of javascript on the
client side but I guess not (I was hopeful though).
 
You have to use javascript. Your in the web world now.

Take a look at teh code below.

Regards

John Timney (MVP)
http://www.johntimney.com


html>
<head>
<script language="VB" runat="server">
'Sub Page_PreRender()
Sub Page_Load( sender as Object,e as EventArgs)
'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
DoClick() {"
ScriptString += "var truthBeTold = window.confirm('Click OK to continue.
Click Cancel to stop.');"
ScriptString += "if (truthBeTold)"
ScriptString += "window.alert('Welcome to MVP World!');"
ScriptString += "else window.alert('Bye from MVP World!');}<"
scriptString += "/"
scriptString += "script>"
If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>
 
John said:
You have to use javascript. Your in the web world now.

Take a look at teh code below.

Regards

John Timney (MVP)
http://www.johntimney.com


html>
<head>
<script language="VB" runat="server">
'Sub Page_PreRender()
Sub Page_Load( sender as Object,e as EventArgs)
'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
DoClick() {"
ScriptString += "var truthBeTold = window.confirm('Click OK to continue.
Click Cancel to stop.');"
ScriptString += "if (truthBeTold)"
ScriptString += "window.alert('Welcome to MVP World!');"
ScriptString += "else window.alert('Bye from MVP World!');}<"
scriptString += "/"
scriptString += "script>"
If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>

Thanks John. I'll make good use of it.
 
Back
Top