Javascript in VB class

Discussion in 'ASP .Net' started by Brian Henry, Jun 11, 2004.

  1. Brian Henry

    Brian Henry Guest

    Is there a way to launch a javascript command from within VB code? For
    instance, to issue a window.open(some url) if a certain condition is met. I
    know you can add the javacript to a control event at runtime, but i need to
    just launch it, not wait for the user to click something.

    Thanks
     
    Brian Henry, Jun 11, 2004
    #1
    1. Advertising

  2. No. "VB Code" is server-side. JavaScript is client-side. And never the twain
    shall meet.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Brian Henry" <> wrote in message
    news:#W#...
    > Is there a way to launch a javascript command from within VB code? For
    > instance, to issue a window.open(some url) if a certain condition is met.

    I
    > know you can add the javacript to a control event at runtime, but i need

    to
    > just launch it, not wait for the user to click something.
    >
    > Thanks
    >
    >
     
    Kevin Spencer, Jun 11, 2004
    #2
    1. Advertising

  3. Brian Henry

    Patrice Guest

    Just bind your javascript to the appropriate client side event (such as the
    the onload attribute of the body tag). It will be always performed client
    side anyway.

    Patrice

    --

    "Brian Henry" <> a écrit dans le message de
    news:%23W%...
    > Is there a way to launch a javascript command from within VB code? For
    > instance, to issue a window.open(some url) if a certain condition is met.

    I
    > know you can add the javacript to a control event at runtime, but i need

    to
    > just launch it, not wait for the user to click something.
    >
    > Thanks
    >
    >
     
    Patrice, Jun 11, 2004
    #3
  4. "Brian Henry" <> wrote in message
    news:%23W%...
    > Is there a way to launch a javascript command from within VB code? For
    > instance, to issue a window.open(some url) if a certain condition is met.

    I
    > know you can add the javacript to a control event at runtime, but i need

    to
    > just launch it, not wait for the user to click something.


    JavaScript is just text in a response the server sends to the client. Unless
    you are sending text to the client, there will be no JavaScript. The only
    time you can send text to the client is at the end of the request.

    Also, you seem to have some code, and you want that code to launch some
    JavaScript. But how did that code get called if the user didn't click
    anything?
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 11, 2004
    #4
  5. Brian Henry

    Brian Henry Guest

    It's kind of like a validation function, kind of hard to explain.
    Basically, when the user clicks a button, i want to run a small function,
    and then if and only if a certain condition fails do i run the javascript.

    "John Saunders" <> wrote in message
    news:...
    > "Brian Henry" <> wrote in message
    > news:%23W%...
    > > Is there a way to launch a javascript command from within VB code? For
    > > instance, to issue a window.open(some url) if a certain condition is

    met.
    > I
    > > know you can add the javacript to a control event at runtime, but i need

    > to
    > > just launch it, not wait for the user to click something.

    >
    > JavaScript is just text in a response the server sends to the client.

    Unless
    > you are sending text to the client, there will be no JavaScript. The only
    > time you can send text to the client is at the end of the request.
    >
    > Also, you seem to have some code, and you want that code to launch some
    > JavaScript. But how did that code get called if the user didn't click
    > anything?
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
     
    Brian Henry, Jun 11, 2004
    #5
  6. "Brian Henry" <> wrote in message
    news:...
    > It's kind of like a validation function, kind of hard to explain.
    > Basically, when the user clicks a button, i want to run a small function,
    > and then if and only if a certain condition fails do i run the javascript.


    I'm sorry, but I'm afraid you're should learn a bit more about the execution
    model of ASP.NET before tackling this task. Perhaps this will help: The
    ASP.NET Page Object Model
    (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm
    l/aspnet-pageobjectmodel.asp?frame=true). Realize that this happens on the
    initial request, and on _every_ postback.
    --
    John Saunders
    johnwsaundersiii at hotmail


    > "John Saunders" <> wrote in message
    > news:...
    > > "Brian Henry" <> wrote in message
    > > news:%23W%...
    > > > Is there a way to launch a javascript command from within VB code?

    For
    > > > instance, to issue a window.open(some url) if a certain condition is

    > met.
    > > I
    > > > know you can add the javacript to a control event at runtime, but i

    need
    > > to
    > > > just launch it, not wait for the user to click something.

    > >
    > > JavaScript is just text in a response the server sends to the client.

    > Unless
    > > you are sending text to the client, there will be no JavaScript. The

    only
    > > time you can send text to the client is at the end of the request.
    > >
    > > Also, you seem to have some code, and you want that code to launch some
    > > JavaScript. But how did that code get called if the user didn't click
    > > anything?
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >

    >
    >
     
    John Saunders, Jun 11, 2004
    #6
  7. If you want to validate something in client side code before you
    submit, bind a client side event to your submit button.


    **** server code ****
    myBtn.Attributes.Add("OnClick","return Validate();");


    **** client code ****
    function Validate() {
    // do some logic
    return true or false;
    }

    when the use clicks the button, the client side validation method is
    called, and if you return true, the form will post.
     
    Justin Beckwith, Jun 12, 2004
    #7
  8. Brian Henry

    Anand Sagar Guest

    Eg. VB.Net code:

    If flag = true the
    response.write("<script language = 'javascript'>alert('the flag was
    succesful');</script>")
    else
    response.write("<script language = 'javascript'>alert('the flag was
    Unsuccesful');</script>")
    end if


    Sagar.

    "Brian Henry" <> wrote in message
    news:%23W%...
    > Is there a way to launch a javascript command from within VB code? For
    > instance, to issue a window.open(some url) if a certain condition is met.

    I
    > know you can add the javacript to a control event at runtime, but i need

    to
    > just launch it, not wait for the user to click something.
    >
    > Thanks
    >
    >
     
    Anand Sagar, Jun 16, 2004
    #8
  9. "Anand Sagar" <> wrote in message
    news:...
    > Eg. VB.Net code:
    >
    > If flag = true the
    > response.write("<script language = 'javascript'>alert('the flag was
    > succesful');</script>")
    > else
    > response.write("<script language = 'javascript'>alert('the flag was
    > Unsuccesful');</script>")
    > end if


    This VB.NET code will have been executed in response to a user action, e.g.
    a click.
    --
    John Saunders
    johnwsaundersiii at hotmail


    > "Brian Henry" <> wrote in message
    > news:%23W%...
    > > Is there a way to launch a javascript command from within VB code? For
    > > instance, to issue a window.open(some url) if a certain condition is

    met.
    > I
    > > know you can add the javacript to a control event at runtime, but i need

    > to
    > > just launch it, not wait for the user to click something.
    > >
    > > Thanks
    > >
    > >

    >
    >
     
    John Saunders, Jun 16, 2004
    #9
  10. What if I wanted to call my of function test() ? How would I do that?

    Response.Write("<script language = 'javascript'>test();</script>");

    ....dows not work



    "Anand Sagar" <> wrote in message
    news:...
    > Eg. VB.Net code:
    >
    > If flag = true the
    > response.write("<script language = 'javascript'>alert('the flag was
    > succesful');</script>")
    > else
    > response.write("<script language = 'javascript'>alert('the flag was
    > Unsuccesful');</script>")
    > end if
    >
    >
    > Sagar.
    >
    > "Brian Henry" <> wrote in message
    > news:%23W%...
    > > Is there a way to launch a javascript command from within VB code? For
    > > instance, to issue a window.open(some url) if a certain condition is

    met.
    > I
    > > know you can add the javacript to a control event at runtime, but i need

    > to
    > > just launch it, not wait for the user to click something.
    > >
    > > Thanks
    > >
    > >

    >
    >
     
    Alexander Kaplunov, Jun 17, 2004
    #10
  11. "Alexander Kaplunov" <> wrote in message
    news:OzZURz$...
    > What if I wanted to call my of function test() ? How would I do that?
    >
    > Response.Write("<script language = 'javascript'>test();</script>");
    >
    > ...dows not work


    Could you please provide some detail? Exactly how does it "not work"?

    And did you define a function called "test"?
    --
    John Saunders
    johnwsaundersiii at hotmail


    > "Anand Sagar" <> wrote in message
    > news:...
    > > Eg. VB.Net code:
    > >
    > > If flag = true the
    > > response.write("<script language = 'javascript'>alert('the flag was
    > > succesful');</script>")
    > > else
    > > response.write("<script language = 'javascript'>alert('the flag was
    > > Unsuccesful');</script>")
    > > end if
    > >
    > >
    > > Sagar.
    > >
    > > "Brian Henry" <> wrote in message
    > > news:%23W%...
    > > > Is there a way to launch a javascript command from within VB code?

    For
    > > > instance, to issue a window.open(some url) if a certain condition is

    > met.
    > > I
    > > > know you can add the javacript to a control event at runtime, but i

    need
    > > to
    > > > just launch it, not wait for the user to click something.
    > > >
    > > > Thanks
    > > >
    > > >

    > >
    > >

    >
    >
     
    John Saunders, Jun 17, 2004
    #11
  12. Yes I do have test function defined.

    When I execute the code I get error on the page "Error: Object expected"

    I can execute alert(), window.open(), etc. functions but not functions that
    I define.

    Thanks for your help.
    Alex.

    "John Saunders" <> wrote in message
    news:#...
    > "Alexander Kaplunov" <> wrote in message
    > news:OzZURz$...
    > > What if I wanted to call my of function test() ? How would I do that?
    > >
    > > Response.Write("<script language = 'javascript'>test();</script>");
    > >
    > > ...dows not work

    >
    > Could you please provide some detail? Exactly how does it "not work"?
    >
    > And did you define a function called "test"?
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    > > "Anand Sagar" <> wrote in message
    > > news:...
    > > > Eg. VB.Net code:
    > > >
    > > > If flag = true the
    > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > succesful');</script>")
    > > > else
    > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > Unsuccesful');</script>")
    > > > end if
    > > >
    > > >
    > > > Sagar.
    > > >
    > > > "Brian Henry" <> wrote in message
    > > > news:%23W%...
    > > > > Is there a way to launch a javascript command from within VB code?

    > For
    > > > > instance, to issue a window.open(some url) if a certain condition is

    > > met.
    > > > I
    > > > > know you can add the javacript to a control event at runtime, but i

    > need
    > > > to
    > > > > just launch it, not wait for the user to click something.
    > > > >
    > > > > Thanks
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alexander Kaplunov, Jun 17, 2004
    #12
  13. "Alexander Kaplunov" <> wrote in message
    news:...
    > Yes I do have test function defined.
    >
    > When I execute the code I get error on the page "Error: Object expected"
    >
    > I can execute alert(), window.open(), etc. functions but not functions

    that
    > I define.


    Can you create a reproducer and show us the code?
    --
    John Saunders
    johnwsaundersiii at hotmail

    > "John Saunders" <> wrote in message
    > news:#...
    > > "Alexander Kaplunov" <> wrote in message
    > > news:OzZURz$...
    > > > What if I wanted to call my of function test() ? How would I do that?
    > > >
    > > > Response.Write("<script language = 'javascript'>test();</script>");
    > > >
    > > > ...dows not work

    > >
    > > Could you please provide some detail? Exactly how does it "not work"?
    > >
    > > And did you define a function called "test"?
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >
    > > > "Anand Sagar" <> wrote in message
    > > > news:...
    > > > > Eg. VB.Net code:
    > > > >
    > > > > If flag = true the
    > > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > > succesful');</script>")
    > > > > else
    > > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > > Unsuccesful');</script>")
    > > > > end if
    > > > >
    > > > >
    > > > > Sagar.
    > > > >
    > > > > "Brian Henry" <> wrote in message
    > > > > news:%23W%...
    > > > > > Is there a way to launch a javascript command from within VB code?

    > > For
    > > > > > instance, to issue a window.open(some url) if a certain condition

    is
    > > > met.
    > > > > I
    > > > > > know you can add the javacript to a control event at runtime, but

    i
    > > need
    > > > > to
    > > > > > just launch it, not wait for the user to click something.
    > > > > >
    > > > > > Thanks
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    John Saunders, Jun 17, 2004
    #13
  14. Sure. Here is it:

    Client code:

    function test()
    {
    alert("Got test!");
    }

    Code-behind (server)
    public void Button2_Click(object sender, System.EventArgs e)
    {

    Response.Write("<script language='javascript'>test();</script>");

    }



    Thanks, Alex.

    "John Saunders" <> wrote in message news:...
    > "Alexander Kaplunov" <> wrote in message
    > news:...
    > > Yes I do have test function defined.
    > >
    > > When I execute the code I get error on the page "Error: Object expected"
    > >
    > > I can execute alert(), window.open(), etc. functions but not functions

    > that
    > > I define.

    >
    > Can you create a reproducer and show us the code?
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    > > "John Saunders" <> wrote in message
    > > news:#...
    > > > "Alexander Kaplunov" <> wrote in message
    > > > news:OzZURz$...
    > > > > What if I wanted to call my of function test() ? How would I do that?
    > > > >
    > > > > Response.Write("<script language = 'javascript'>test();</script>");
    > > > >
    > > > > ...dows not work
    > > >
    > > > Could you please provide some detail? Exactly how does it "not work"?
    > > >
    > > > And did you define a function called "test"?
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >
    > > > > "Anand Sagar" <> wrote in message
    > > > > news:...
    > > > > > Eg. VB.Net code:
    > > > > >
    > > > > > If flag = true the
    > > > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > > > succesful');</script>")
    > > > > > else
    > > > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > > > Unsuccesful');</script>")
    > > > > > end if
    > > > > >
    > > > > >
    > > > > > Sagar.
    > > > > >
    > > > > > "Brian Henry" <> wrote in message
    > > > > > news:%23W%...
    > > > > > > Is there a way to launch a javascript command from within VB code?
    > > > For
    > > > > > > instance, to issue a window.open(some url) if a certain condition

    > is
    > > > > met.
    > > > > > I
    > > > > > > know you can add the javacript to a control event at runtime, but

    > i
    > > > need
    > > > > > to
    > > > > > > just launch it, not wait for the user to click something.
    > > > > > >
    > > > > > > Thanks
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alexander Kaplunov, Jun 17, 2004
    #14
  15. Brian Henry

    Anand Sagar Guest

    You cannot call a explicitly written at design time js function from a
    Response.Write call. You have to write the complete text of the function at
    run-time

    Here is a VB.Net code for it.

    Dim JString as String

    jString = "function Test(){"
    jString += "alert('this is a line inside the finction');"
    jString += "}"

    Response.Write("<script language = 'javascript'>" + jString + "</script>")


    "Alexander Kaplunov" <> wrote in message
    news:OzZURz$...
    > What if I wanted to call my of function test() ? How would I do that?
    >
    > Response.Write("<script language = 'javascript'>test();</script>");
    >
    > ...dows not work
    >
    >
    >
    > "Anand Sagar" <> wrote in message
    > news:...
    > > Eg. VB.Net code:
    > >
    > > If flag = true the
    > > response.write("<script language = 'javascript'>alert('the flag was
    > > succesful');</script>")
    > > else
    > > response.write("<script language = 'javascript'>alert('the flag was
    > > Unsuccesful');</script>")
    > > end if
    > >
    > >
    > > Sagar.
    > >
    > > "Brian Henry" <> wrote in message
    > > news:%23W%...
    > > > Is there a way to launch a javascript command from within VB code?

    For
    > > > instance, to issue a window.open(some url) if a certain condition is

    > met.
    > > I
    > > > know you can add the javacript to a control event at runtime, but i

    need
    > > to
    > > > just launch it, not wait for the user to click something.
    > > >
    > > > Thanks
    > > >
    > > >

    > >
    > >

    >
    >
     
    Anand Sagar, Jun 17, 2004
    #15
  16. This code does not cause an error but it does not call the Test() function
    either. Basically, nothing happens.

    Alex.

    "Anand Sagar" <> wrote in message
    news:uZNlA#...
    > You cannot call a explicitly written at design time js function from a
    > Response.Write call. You have to write the complete text of the function

    at
    > run-time
    >
    > Here is a VB.Net code for it.
    >
    > Dim JString as String
    >
    > jString = "function Test(){"
    > jString += "alert('this is a line inside the finction');"
    > jString += "}"
    >
    > Response.Write("<script language = 'javascript'>" + jString +

    "</script>")
    >
    >
    > "Alexander Kaplunov" <> wrote in message
    > news:OzZURz$...
    > > What if I wanted to call my of function test() ? How would I do that?
    > >
    > > Response.Write("<script language = 'javascript'>test();</script>");
    > >
    > > ...dows not work
    > >
    > >
    > >
    > > "Anand Sagar" <> wrote in message
    > > news:...
    > > > Eg. VB.Net code:
    > > >
    > > > If flag = true the
    > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > succesful');</script>")
    > > > else
    > > > response.write("<script language = 'javascript'>alert('the flag was
    > > > Unsuccesful');</script>")
    > > > end if
    > > >
    > > >
    > > > Sagar.
    > > >
    > > > "Brian Henry" <> wrote in message
    > > > news:%23W%...
    > > > > Is there a way to launch a javascript command from within VB code?

    > For
    > > > > instance, to issue a window.open(some url) if a certain condition is

    > > met.
    > > > I
    > > > > know you can add the javacript to a control event at runtime, but i

    > need
    > > > to
    > > > > just launch it, not wait for the user to click something.
    > > > >
    > > > > Thanks
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alexander Kaplunov, Jun 17, 2004
    #16
  17. Brian Henry

    marcelito69

    Joined:
    Oct 27, 2009
    Messages:
    1
    this is very easy...start with this....write an html page including your javascript...embedd an IE control in your vb form...call the navigate method with your html file as url address....that's it folks!






     
    marcelito69, Oct 27, 2009
    #17
    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. cyril
    Replies:
    2
    Views:
    3,878
    cyril
    Aug 25, 2004
  2. Purush
    Replies:
    4
    Views:
    1,666
    Purush Rudrakshala
    Apr 13, 2005
  3. E11
    Replies:
    1
    Views:
    4,800
    Thomas Weidenfeller
    Oct 12, 2005
  4. christopher diggins
    Replies:
    16
    Views:
    761
    Pete Becker
    May 4, 2005
  5. Joseph Turian
    Replies:
    5
    Views:
    602
Loading...

Share This Page