How to use javascript alert in asp.net with vb

Discussion in 'ASP .Net' started by MWulfe, Apr 30, 2010.

  1. MWulfe

    MWulfe Guest

    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!
     
    MWulfe, Apr 30, 2010
    #1
    1. Advertising

  2. On Apr 30, 1:56 am, MWulfe <> wrote:
    > 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");
     
    Alexey Smirnov, Apr 30, 2010
    #2
    1. Advertising

  3. MWulfe

    Andy B. Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Apr 30, 1:56 am, MWulfe <> wrote:
    > 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?
     
    Andy B., Apr 30, 2010
    #3
  4. "Andy B." <> wrote in message
    news:#...

    > 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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Apr 30, 2010
    #4
  5. MWulfe

    qvo178

    Joined:
    Aug 28, 2008
    Messages:
    19
    You can set it with registerclientscript
     
    qvo178, Apr 30, 2010
    #5
  6. On Apr 30, 9:40 am, "Andy B." <> wrote:
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...
    > On Apr 30, 1:56 am, MWulfe <> wrote:
    >
    > > 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?


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

    aspx
    -----------------
    if (<%=x%>==2 && <%=y%>==3)
    alert("message");
    -----------------

    I think it should work as expected.
     
    Alexey Smirnov, Apr 30, 2010
    #6
  7. MWulfe

    MWulfe Guest

    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.

    "Alexey Smirnov" <> wrote in message
    news:...
    On Apr 30, 9:40 am, "Andy B." <> wrote:
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...
    > On Apr 30, 1:56 am, MWulfe <> wrote:
    >
    > > 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?


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

    aspx
    -----------------
    if (<%=x%>==2 && <%=y%>==3)
    alert("message");
    -----------------

    I think it should work as expected.
     
    MWulfe, May 5, 2010
    #7
  8. On May 5, 6:20 pm, "MWulfe" <> wrote:
    > 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!
     
    Alexey Smirnov, May 5, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michelle Stone

    alert using Javascript with asp.net

    Michelle Stone, Dec 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    598
    Steven Alexander
    Dec 5, 2003
  2. Mersh
    Replies:
    0
    Views:
    526
    Mersh
    Mar 13, 2007
  3. Ganesh
    Replies:
    0
    Views:
    585
    Ganesh
    Jun 29, 2007
  4. JB
    Replies:
    2
    Views:
    3,465
    Cubaman
    Aug 2, 2010
  5. Hans-Marc Olsen
    Replies:
    0
    Views:
    102
    Hans-Marc Olsen
    Nov 16, 2004
Loading...

Share This Page