How to alert message by using VB.NET code in web form
Thank you.
Printable View
How to alert message by using VB.NET code in web form
Thank you.
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');";
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. ?
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.Quote:
Originally Posted by Patch21
Your help is appreciated.
le9569.
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!!!!!Quote:
Originally Posted by Patch21
What a weird thing I've seen before....
Any help?
Thanks.
John.
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.
I need the message box coding for the ASP.NET web forms not for the windows forms. Thanks alot..
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
They were working with the existing Internet architecture. So a messagebox can't just be added by whim, it's limited to the alert()sQuote:
Originally Posted by The Cheat
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.
Quote:
Originally Posted by abcat
you are missing the ; at the end:
strScript &= "alert('Testing');"
still the same error..
What's the error? Also, add a language attribute to the script tag.
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
Quote:
Originally Posted by Patch21
Might I have the audacity to suggest that you read the rest of this thread? :)Quote:
Originally Posted by lekhuyen
'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)