Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Alert Box with VB.net

    Greetings!

    I'm not sure why I'm having a hard time with this. I just want a simple message box to appear (with only 'OK' as a choice) when the page loads. Here are the first few lines of code under the Page_Load sub:

    Code:
    strMessage = "Please go to File --> Page Setup, and select 'Landscape' orientation before printing"
      
    Dim strScript As String = "<script language=JavaScript>alert('" & strMessage & "');</script>"
    
    If (Not Page.IsStartupScriptRegistered("clientScript")) Then
         Page.RegisterStartupScript("clientScript", strScript)
    End If
    Questions: Is this coding right? If so, I'm wondering why I'm getting an error message saying "String constants must end with a double quote"

    I feel really dumb, and am hoping someone can shed some light on my conundrum.

    Thanks much.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Hi,
    the single quotes here:
    Code:
    strMessage = "Please go to File --> Page Setup, and select 'Landscape' orientation before printing"
    Are conflicting with your javascript quotes in your alert, try changing it to this:
    Code:
            Dim strMessage = "Please go to File --> Page Setup, and select " & """Landscape" & """orientation before printing"
    
            Dim strScript As String = "<script language=JavaScript>alert('" & strMessage & "');</script>"
    
            If (Not Page.IsStartupScriptRegistered("clientScript")) Then
                Page.RegisterStartupScript("clientScript", strScript)
            End If
    Good luck;

  • #3
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brandoe,

    Thanks for such a quick reply. I tried your suggestion, and I also tried removing any quotes from the middle of strMessage.

    Getting the same result.

    Also, earlier, I tried using MessageBox.Show....., and it doesn't recognize MessageBox. Is this a possiblity?

    Thanks again!

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I tried the code I posted in the page load event, and everything is working correctly. Possibly something else in your code that we aren't seeing is cuasing the problems. Can we see the rest of the code? MessageBox doesn't exist in asp.net applications, only in windows forms applications, thus, you've gotta incorporate some javascript.

  • #5
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great!

    That'd be swell! Thank you sir.

    By the way...this page worked before I added the above-mentioned lines of code.

    Much obliged!
    Attached Files Attached Files

  • #6
    New Coder
    Join Date
    May 2005
    Location
    The Lone Star State
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved!

    It's funny how the answer can be so simple.

    I pasted the following code snippet above my

    Code:
    <script runat="server">
    and now it works perfectly:

    Code:
    <script language="JavaScript">
    alert("Please go to File --> Page Setup, and select 'Landscape' orientation before printing")
    </script>
    Thanks for the assist!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •