469,266 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

how to display a message box in web application using asp.net?

Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong



Jul 21 '05 #1
9 30904
You have to output the JavaScript command to the browser, which is
window.alert(...), I think.

"yezanxiong" <ye********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #2
<html>
<head>
<script language="C#" runat="server">

void Page_Load( Object sender , EventArgs e )
{

//Form the script that is to be registered at client side.
string ScriptString = "<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(! IsClientScriptBlockRegistered("clientScript"))
{
RegisterClientScriptBlock("clientScript", ScriptString);
}
}

</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"yezanxiong" <ye********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #3
You can also use your own customize messagebox on web by using code
JavaScript Window.showmodal calling some asp
on that asp write this on load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' If IsPostBack Then Exit Sub
Dim msgString As String
Dim btnType As String
msgString = Request.QueryString("msgString")
btnType = Request.QueryString("btnType")
lblCaption.Text = msgString
If btnType = "VBOK" Then
btnOk.Text = "OK"
btnCancel.Visible = False
ElseIf btnType = "VBOKCANCEL" Then
btnOk.Text = "OK"
btnCancel.Text = "Cancel"
ElseIf btnType = "VBYESNO" Then
btnOk.Text = "Yes"
btnCancel.Text = "No"
End If
btnOk.Attributes.Add("onclick", "return CheckValue(1)")
btnCancel.Attributes.Add("onclick", "return CheckValue(0)")
End Sub
window.showmodal will return value as per click and you can perform yuor
opration
"yezanxiong" wrote:
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #4
Thanks. I add 3 control "lblCaption","btnOK","btnCancel" in the web form, and
copy your code to the page_load, I would like to know how I call
window.showmodal?

Yezanxiong

"RiteshDotNet" wrote:
You can also use your own customize messagebox on web by using code
JavaScript Window.showmodal calling some asp
on that asp write this on load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' If IsPostBack Then Exit Sub
Dim msgString As String
Dim btnType As String
msgString = Request.QueryString("msgString")
btnType = Request.QueryString("btnType")
lblCaption.Text = msgString
If btnType = "VBOK" Then
btnOk.Text = "OK"
btnCancel.Visible = False
ElseIf btnType = "VBOKCANCEL" Then
btnOk.Text = "OK"
btnCancel.Text = "Cancel"
ElseIf btnType = "VBYESNO" Then
btnOk.Text = "Yes"
btnCancel.Text = "No"
End If
btnOk.Attributes.Add("onclick", "return CheckValue(1)")
btnCancel.Attributes.Add("onclick", "return CheckValue(0)")
End Sub
window.showmodal will return value as per click and you can perform yuor
opration
"yezanxiong" wrote:
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #5
ret_value=window.showModalDialog("FMfetch.asp?Plan tType=",null,'
dialogWidth:300px;
dialogHeight:300px;left:yes;;status:no');
if(typeof(ret_value)!="undefined")
{
if (ret_value==0)
And perform your operation on the basis of 0/1 yes /no
}
"yezanxiong" wrote:
Thanks. I add 3 control "lblCaption","btnOK","btnCancel" in the web form, and
copy your code to the page_load, I would like to know how I call
window.showmodal?

Yezanxiong

"RiteshDotNet" wrote:
You can also use your own customize messagebox on web by using code
JavaScript Window.showmodal calling some asp
on that asp write this on load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' If IsPostBack Then Exit Sub
Dim msgString As String
Dim btnType As String
msgString = Request.QueryString("msgString")
btnType = Request.QueryString("btnType")
lblCaption.Text = msgString
If btnType = "VBOK" Then
btnOk.Text = "OK"
btnCancel.Visible = False
ElseIf btnType = "VBOKCANCEL" Then
btnOk.Text = "OK"
btnCancel.Text = "Cancel"
ElseIf btnType = "VBYESNO" Then
btnOk.Text = "Yes"
btnCancel.Text = "No"
End If
btnOk.Attributes.Add("onclick", "return CheckValue(1)")
btnCancel.Attributes.Add("onclick", "return CheckValue(0)")
End Sub
window.showmodal will return value as per click and you can perform yuor
opration
"yezanxiong" wrote:
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #6
and pass query string btnType and Message

"yezanxiong" wrote:
Thanks. I add 3 control "lblCaption","btnOK","btnCancel" in the web form, and
copy your code to the page_load, I would like to know how I call
window.showmodal?

Yezanxiong

"RiteshDotNet" wrote:
You can also use your own customize messagebox on web by using code
JavaScript Window.showmodal calling some asp
on that asp write this on load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' If IsPostBack Then Exit Sub
Dim msgString As String
Dim btnType As String
msgString = Request.QueryString("msgString")
btnType = Request.QueryString("btnType")
lblCaption.Text = msgString
If btnType = "VBOK" Then
btnOk.Text = "OK"
btnCancel.Visible = False
ElseIf btnType = "VBOKCANCEL" Then
btnOk.Text = "OK"
btnCancel.Text = "Cancel"
ElseIf btnType = "VBYESNO" Then
btnOk.Text = "Yes"
btnCancel.Text = "No"
End If
btnOk.Attributes.Add("onclick", "return CheckValue(1)")
btnCancel.Attributes.Add("onclick", "return CheckValue(0)")
End Sub
window.showmodal will return value as per click and you can perform yuor
opration
"yezanxiong" wrote:
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #7
Hi All, May I please follow up with the same question that wasasked previously?
I actually hit the same error message when trying to displaymessagebox.show method in ASP.net. I am wondering what is"Userinteractive mode"? How to set it up? Is is something needto be setup either in web.config of each indivdual webform? Orsomething in security.config?

Thanks all in advance.
Tommy
User submitted from AEWNET (http://www.aewnet.com/)
Jul 21 '05 #8
Yezanxiong,

After searching for the same problem myself, and seeing these complicated
responses, I found my own MUCH simpler answer: Add a label to the page,
instead of using response.write.

Create a sub like so:
Private Sub ShowAlert(ByVal Message As String)
Dim MyAlertLabel As New Label
MyAlertLabel.Text = "<script language='vbscript'>" & _
vbNewLine & "Alert(" & """" & Message & """" & ")" & _
vbNewLine & "</script>"
Page.Controls.Add(MyAlertLabel)
End Sub

This will display an alert box without blanking the screen. Adding the new
label did not change the appearance of the page, in the testing I did. It
behaves just like a message box in VB, you can add the ShowAlert("xxx")
within your code wherever you need it, (like in an If statement), it does
not need to be tied to a submit button. For example, you can make it pop up
when the user types in an invalid value on your form.
One suggestion: You do have to make sure to use "VbCrLf" as a newline
character (instead of "VbNewLine") when creating your message, or it will
cause an error on the page.

--
Christopher W. Douglas
www (dot) douglasweb (dot) com
chris (at) douglasweb (dot) com
"yezanxiong" <ye********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello all,

I am new in asp.net developer,I would like to ask a simple question. how to display a message box in web application using asp.net?

If I just use

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
MsgBox("please enter the correct user name and password",
MsgBoxStyle.Information, "Failed in login")
End Sub

when it run, it prompt : It is invalid to show a modal dialog or form when
the application is not running in UserInteractive mode. Specify the
ServiceNotification or DefaultDesktopOnly style to display a notification
from a service application.

Anyone can help me to solve this question? Thanks.

Yezanxiong


Jul 21 '05 #9
Hi,

I did not see this message earlier, In my sample bellow I show you the the
actual messagebox in a webform, I did not see it in this thread (I hope I
did not missed him). It is the "prompt" not the textbox you see in this
sample, that is to set the information in when it is received from the
messagebox. In the way in this sample is now it looksuglier than ugly can
be.
The sample need a button and a textbox on a form.
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
If Not IsPostBack Then
Dim alertScript As String = _
"<script language=JavaScript>document.all.item('TextBox1'). value
" & _
" = prompt('Give me some text','I hope this helps, Cor');
</script>"
RegisterStartupScript("Startup", alertScript)
Else
str = TextBox1.Text
End If
End Sub
///

I hope this helps a little bit?

Cor
Jul 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by ZRexRider | last post: by
1 post views Thread by John | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.