How to use javascript alert in asp.net with vb

  • Thread starter Thread starter MWulfe
  • Start date Start date
M

MWulfe

I want to use javascript to do the equivalent to this Windows Form
code on an asp.net webpage using VB:

if x = 2 and y = 3 then
messagebox.show("This is a message")
end if

Many of the code I've found appears to be obsolete or includes lots of
other bells and whistles (adding an alert to a datagrid or a control
attribute), which I do not need and only find confusing. I'm using
Web Developer Express 2008.

Help would be appreciated! Thanks!
 
I want to use javascript to do the equivalent to this Windows Form
code on an asp.net webpage using VB:

if x = 2 and y = 3 then
        messagebox.show("This is a message")
end if

Many of the code I've found appears to be obsolete or includes lots of
other bells and whistles (adding an alert to a datagrid or a control
attribute), which I do not need and only find confusing.  I'm using
Web Developer Express 2008.

Help would be appreciated!  Thanks!

if (x==2 && y==3)
alert("message");
 
I want to use javascript to do the equivalent to this Windows Form
code on an asp.net webpage using VB:

if x = 2 and y = 3 then
messagebox.show("This is a message")
end if

Many of the code I've found appears to be obsolete or includes lots of
other bells and whistles (adding an alert to a datagrid or a control
attribute), which I do not need and only find confusing. I'm using
Web Developer Express 2008.

Help would be appreciated! Thanks!

if (x==2 && y==3)
alert("message");

How do you do that from the vb codebehind?
 
How do you do that from the VB codebehind?

Probably something like:

If x = 2 And y = 3 Then
ClientScriptManager.RegisterStartupScript(Me.GetType, "message",
"alert('This is a message');", True)
End If
 
if (x==2 && y==3)
alert("message");

How do you do that from the vb codebehind?

Sure, it's inline javascript. I think, he didn't mention that it must
be from the codebehind.

In addition to example by Mark, this can be done using public
variables as

vb.net
-----------------
Protected Dim x As Integer = 2
Protected Dim y As Integer = 3
 
In fact I did end up using the in-line javascript and it works just fine.
The only minor drawbacks are that the screen goes blank on some systems but
only while the message is displayed, there is no flexibility is the dialog
title, the text in the message cannot really be formated, and there is
always a "beep" when the message is displayed. Still, it is a relatively
simple solution and it works consistently.

if (x==2 && y==3)
alert("message");

How do you do that from the vb codebehind?

Sure, it's inline javascript. I think, he didn't mention that it must
be from the codebehind.

In addition to example by Mark, this can be done using public
variables as

vb.net
-----------------
Protected Dim x As Integer = 2
Protected Dim y As Integer = 3
 
In fact I did end up using the in-line javascript and it works just fine.
The only minor drawbacks are that the screen goes blank on some systems but
only while the message is displayed, there is no flexibility is the dialog
title, the text in the message cannot really be formated, and there is
always a "beep" when the message is displayed.  Still, it is a relatively
simple solution and it works consistently.

You can think about using Web2.0/ASP.NET way by implementing
ModalPopupExtender. The ModalPopup extender allows to display a free
designed "popup" in a similar manner which prevents the user from
interacting with the rest of the page. The popup can be shown via
server in code behind and on the client in script. It can be designed
in any way and you can have any title and no beep would occurred. This
would not require any big changes in code, but in application
configuration (you would need to download and include
AjaxControlToolkit and setup it in the web.config file. More about
ModalPopupExtender and AjaxControlToolkit you can find here

http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

Cheers!
 
Back
Top