Results 1 to 17 of 17

Thread: Message box in ASP.NET Webform

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    bangkok
    Posts
    4

    Message box in ASP.NET Webform

    How to alert message by using VB.NET code in web form
    Thank you.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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');";

  3. #3
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    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. ?

  4. #4
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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:
    1. Dim msgBox As Windows.Forms.MessageBox
    2. Dim Action As Windows.Forms.DialogResult
    3.  
    4. 'display messagebox
    5. Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
    6. Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
    7.  
    8. Select Case Action
    9.         Case Windows.Forms.DialogResult.Yes
    10.                'do something
    11.         Case Windows.Forms.DialogResult.No
    12.                'do something
    13.         Case Windows.Forms.DialogResult.Cancel
    14.                'do something
    15. End Select

    If you do use this code, you are presuming that the client browsing your site has a windows operating system.

  5. #5
    New Member
    Join Date
    Jan 2005
    Posts
    8

    Re: Message box in ASP.NET Webform

    Quote 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:
    1. Dim msgBox As Windows.Forms.MessageBox
    2. Dim Action As Windows.Forms.DialogResult
    3.  
    4. 'display messagebox
    5. Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
    6. Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
    7.  
    8. Select Case Action
    9.         Case Windows.Forms.DialogResult.Yes
    10.                'do something
    11.         Case Windows.Forms.DialogResult.No
    12.                'do something
    13.         Case Windows.Forms.DialogResult.Cancel
    14.                'do something
    15. 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.

  6. #6
    New Member
    Join Date
    Jan 2005
    Posts
    8

    Re: Message box in ASP.NET Webform

    Quote 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:
    1. Dim msgBox As Windows.Forms.MessageBox
    2. Dim Action As Windows.Forms.DialogResult
    3.  
    4. 'display messagebox
    5. Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
    6. Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
    7.  
    8. Select Case Action
    9.         Case Windows.Forms.DialogResult.Yes
    10.                'do something
    11.         Case Windows.Forms.DialogResult.No
    12.                'do something
    13.         Case Windows.Forms.DialogResult.Cancel
    14.                'do something
    15. 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.

  7. #7
    Member
    Join Date
    Sep 2004
    Posts
    45

    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.

  8. #8
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    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..

  9. #9
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    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

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Message box in ASP.NET Webform

    Quote 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

  11. #11
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    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.

  12. #12
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: Message box in ASP.NET Webform

    Quote 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');"
    ~Ryan





    Have I helped you? Please Rate my posts.

  13. #13
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    Re: Message box in ASP.NET Webform

    still the same error..

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Message box in ASP.NET Webform

    What's the error? Also, add a language attribute to the script tag.

  15. #15
    Lively Member lekhuyen's Avatar
    Join Date
    May 2006
    Posts
    80

    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

    Quote 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:
    1. Dim msgBox As Windows.Forms.MessageBox
    2. Dim Action As Windows.Forms.DialogResult
    3.  
    4. 'display messagebox
    5. Action = msgBox.Show("Hello?", "Hello World", Windows.Forms.MessageBoxButtons.YesNoCancel, _
    6. Windows.Forms.MessageBoxIcon.Exclamation, Windows.Forms.MessageBoxDefaultButton.Button2, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
    7.  
    8. Select Case Action
    9.         Case Windows.Forms.DialogResult.Yes
    10.                'do something
    11.         Case Windows.Forms.DialogResult.No
    12.                'do something
    13.         Case Windows.Forms.DialogResult.Cancel
    14.                'do something
    15. End Select

    If you do use this code, you are presuming that the client browsing your site has a windows operating system.

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Message box in ASP.NET Webform

    Quote 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?

  17. #17
    New Member
    Join Date
    Mar 2012
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width