473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascript in VB class

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
Nov 18 '05 #1
16 2151
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" <br**********@newsgroups.nospam> a écrit dans le message de
news:%2******************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #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" <br**********@newsgroups.nospam> wrote in message
news:#W**************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #3
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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
Nov 18 '05 #4
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" <jo**************@notcoldmail.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #5
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
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/de...-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" <jo**************@notcoldmail.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #6
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.
Nov 18 '05 #7
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #8
"Anand Sagar" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #9
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #10
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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



Nov 18 '05 #11
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" <jo**************@notcoldmail.com> wrote in message
news:#a**************@tk2msftngp13.phx.gbl...
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Nov 18 '05 #12
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP09.phx.gbl...
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" <jo**************@notcoldmail.com> wrote in message
news:#a**************@tk2msftngp13.phx.gbl...
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
> 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" <br**********@newsgroups.nospam> wrote in message
> news:%2******************@TK2MSFTNGP10.phx.gbl...
> > 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
> >
> >
>
>



Nov 18 '05 #13
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" <jo**************@notcoldmail.com> wrote in message news:uC*************@tk2msftngp13.phx.gbl...
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP09.phx.gbl...
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" <jo**************@notcoldmail.com> wrote in message
news:#a**************@tk2msftngp13.phx.gbl...
"Alexander Kaplunov" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
> 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" <ba******@yahoo.com> wrote in message
> news:eP**************@TK2MSFTNGP12.phx.gbl...
> > 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" <br**********@newsgroups.nospam> wrote in message
> > news:%2******************@TK2MSFTNGP10.phx.gbl...
> > > 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
> > >
> > >
> >
> >
>
>



Nov 18 '05 #14
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" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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



Nov 18 '05 #15
This code does not cause an error but it does not call the Test() function
either. Basically, nothing happens.

Alex.

"Anand Sagar" <ba******@yahoo.com> wrote in message
news:uZ*************@tk2msftngp13.phx.gbl...
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" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Nov 18 '05 #16
This code does not cause an error but it does not call the Test() function
either. Basically, nothing happens.

Alex.

"Anand Sagar" <ba******@yahoo.com> wrote in message
news:uZ*************@tk2msftngp13.phx.gbl...
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" <ka******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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" <ba******@yahoo.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
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" <br**********@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Nov 18 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
7
by: Wm.M.Thompson | last post by:
For a computer programmer JavaScript is not difficult. It is pretty easy to look at some code for the first time and figure out what is going on. This is especially true if you have gratuated...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
8
by: rajesh | last post by:
< script language = javascript c =...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.