PDA

View Full Version : Alert Box with VB.net



reverendleo
10-18-2005, 08:15 PM
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:


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.

Brandoe85
10-18-2005, 08:23 PM
Hi,
the single quotes here:


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:


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;

reverendleo
10-18-2005, 08:34 PM
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!

Brandoe85
10-18-2005, 08:41 PM
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.

reverendleo
10-18-2005, 08:59 PM
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!

reverendleo
10-24-2005, 03:46 PM
It's funny how the answer can be so simple.

I pasted the following code snippet above my


<script runat="server">

and now it works perfectly:


<script language="JavaScript">
alert("Please go to File --> Page Setup, and select 'Landscape' orientation before printing")
</script>

Thanks for the assist!