|
-
Sep 4th, 2003, 08:31 AM
#1
Thread Starter
New Member
Message box in ASP.NET Webform
How to alert message by using VB.NET code in web form
Thank you.
-
Sep 4th, 2003, 09:45 AM
#2
PowerPoster
You have to use client-side javascript.
Here is a code snippet (Add a button to the form):
Code:
// add this to the page load event
SayHello.Attributes["onClick"] = "alert('Hello World');";
-
Mar 4th, 2005, 11:26 AM
#3
Hyperactive Member
Re: Message box in ASP.NET Webform
Is it possible to make the message box like VB that can choose between several icons and it also have the same attributes on some button like ok, cancel etc. ?
-
Mar 4th, 2005, 01:58 PM
#4
Addicted Member
Re: Message box in ASP.NET Webform
Do you mean a vb messagebox as in a windows form message box?
if so, you can use this code
VB Code:
Dim msgBox As Windows.Forms.MessageBox
Dim Action As Windows.Forms.DialogResult
'display messagebox
Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
Select Case Action
Case Windows.Forms.DialogResult.Yes
'do something
Case Windows.Forms.DialogResult.No
'do something
Case Windows.Forms.DialogResult.Cancel
'do something
End Select
If you do use this code, you are presuming that the client browsing your site has a windows operating system.
-
Mar 4th, 2005, 04:34 PM
#5
New Member
Re: Message box in ASP.NET Webform
 Originally Posted by Patch21
Do you mean a vb messagebox as in a windows form message box?
if so, you can use this code
VB Code:
Dim msgBox As Windows.Forms.MessageBox
Dim Action As Windows.Forms.DialogResult
'display messagebox
Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
Select Case Action
Case Windows.Forms.DialogResult.Yes
'do something
Case Windows.Forms.DialogResult.No
'do something
Case Windows.Forms.DialogResult.Cancel
'do something
End Select
If you do use this code, you are presuming that the client browsing your site has a windows operating system.
This is perfect. One thing I guess you already now. In NO selection, I want to close its window. How do I do it? I am sure this function should be in in javascript but I have no idea how to call this javascript function in NO case.
Your help is appreciated.
le9569.
-
Mar 4th, 2005, 05:59 PM
#6
New Member
Re: Message box in ASP.NET Webform
 Originally Posted by Patch21
Do you mean a vb messagebox as in a windows form message box?
if so, you can use this code
VB Code:
Dim msgBox As Windows.Forms.MessageBox
Dim Action As Windows.Forms.DialogResult
'display messagebox
Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
Select Case Action
Case Windows.Forms.DialogResult.Yes
'do something
Case Windows.Forms.DialogResult.No
'do something
Case Windows.Forms.DialogResult.Cancel
'do something
End Select
If you do use this code, you are presuming that the client browsing your site has a windows operating system.
One thing I noticed that when I use this block of code, the confirmation messagebox displays on the web server!!!!!!! Not on user's browser!!!!!
What a weird thing I've seen before....
Any help?
Thanks.
John.
-
Mar 7th, 2005, 02:16 PM
#7
Member
Re: Message box in ASP.NET Webform
That is the only way that particular code will work. I am not sure why MS didn't add a msgbox web control to the toolbox or warn the developer that the msgbox will olny show the message on the server, which as you know, is useless but they didn't. To get the same functionality on a web page you are going to have to use client side JavaScript. If you do a search you should be able to find plenty of sample code. If not post back and I think I can dig one up for you.
Last edited by The Cheat; Mar 7th, 2005 at 02:20 PM.
-
Mar 10th, 2005, 10:48 AM
#8
Hyperactive Member
Re: Message box in ASP.NET Webform
I need the message box coding for the ASP.NET web forms not for the windows forms. Thanks alot..
-
Mar 10th, 2005, 11:01 AM
#9
Frenzied Member
Re: Message box in ASP.NET Webform
Example:
Code:
Sub Button1_Click
Dim strScript As String
Try
strScript = "<script>"
strScript &= "alert('Testing');"
strScript &= "</script>"
Page.RegisterStartupScript("ClientSideScript", strScript)
Catch ex As Exception
Response.write(ex.Message & "<br>" & ex.StackTrace)
End Try
End Sub
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 11th, 2005, 12:57 AM
#10
Re: Message box in ASP.NET Webform
 Originally Posted by The Cheat
That is the only way that particular code will work. I am not sure why MS didn't add a msgbox web control to the toolbox or warn the developer that the msgbox will olny show the message on the server, which as you know, is useless but they didn't. To get the same functionality on a web page you are going to have to use client side JavaScript. If you do a search you should be able to find plenty of sample code. If not post back and I think I can dig one up for you.
They were working with the existing Internet architecture. So a messagebox can't just be added by whim, it's limited to the alert()s
-
Mar 11th, 2005, 09:34 AM
#11
Hyperactive Member
Re: Message box in ASP.NET Webform
Private Sub tb_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_submit.Click
Dim bl As New SuppliersService.Service1
bl.create(tb_personName.Text, tb_companyName.Text, CInt(tb_hpNo.Text), CInt(tb_comNo.Text), tb_location.Text)
Dim strScript As String
Try
strScript = "<script>"
strScript &= "alert('Testing')"
strScript &= "</script>"
Page.RegisterStartupScript("ClientSideScript", strScript)
Catch ex As Exception
Response.Write(ex.Message & "<br>" & ex.StackTrace)
End Try
End Sub
The bold line seems to have error and I need the message box to display like windows form message box that is only Ok Button or Cancel and more functions.
-
Mar 11th, 2005, 09:40 AM
#12
Addicted Member
Re: Message box in ASP.NET Webform
 Originally Posted by abcat
Private Sub tb_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_submit.Click
Dim bl As New SuppliersService.Service1
bl.create(tb_personName.Text, tb_companyName.Text, CInt(tb_hpNo.Text), CInt(tb_comNo.Text), tb_location.Text)
Dim strScript As String
Try
strScript = "<script>"
strScript &= "alert('Testing')"
strScript &= "</script>"
Page.RegisterStartupScript("ClientSideScript", strScript)
Catch ex As Exception
Response.Write(ex.Message & "<br>" & ex.StackTrace)
End Try
End Sub
The bold line seems to have error and I need the message box to display like windows form message box that is only Ok Button or Cancel and more functions.
you are missing the ; at the end:
strScript &= "alert('Testing');"
-
Mar 11th, 2005, 08:39 PM
#13
Hyperactive Member
Re: Message box in ASP.NET Webform
-
Mar 12th, 2005, 04:49 AM
#14
Re: Message box in ASP.NET Webform
What's the error? Also, add a language attribute to the script tag.
-
Jun 22nd, 2006, 02:53 AM
#15
Lively Member
Re: Message box in ASP.NET Webform
I've tried your code but it shows this message (Page error)
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
 Originally Posted by Patch21
Do you mean a vb messagebox as in a windows form message box?
if so, you can use this code
VB Code:
Dim msgBox As Windows.Forms.MessageBox
Dim Action As Windows.Forms.DialogResult
'display messagebox
Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
Select Case Action
Case Windows.Forms.DialogResult.Yes
'do something
Case Windows.Forms.DialogResult.No
'do something
Case Windows.Forms.DialogResult.Cancel
'do something
End Select
If you do use this code, you are presuming that the client browsing your site has a windows operating system.
-
Jun 24th, 2006, 12:09 PM
#16
Re: Message box in ASP.NET Webform
 Originally Posted by lekhuyen
I've tried your code but it shows this message (Page error)
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
Might I have the audacity to suggest that you read the rest of this thread?
-
Nov 5th, 2014, 10:07 PM
#17
New Member
Re: Message box in ASP.NET Webform
'ASP.net MessageBox
'Add a scriptmanager to the ASP.Net Page
<asp:scriptmanager id="ScriptManager1" runat="server" />
try:
Dim sMsg As String = "My Message"
ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "alert('" & sMsg & "')", True)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|