Very simple question on Javascript with ASP button

F

Frag

Hi guys,

I searched around without any clear answer. Tons of stuff, but nothing concrete.

I am trying to call this Javascript function:

function ButtonClicked()
{
alert("The button has been clicked.");
}

Calling it from an HTML button is no problem at all. But there is no way I can call that function from an ASP button. I tried from the HTML side or the aspx side.

I understood that an ASP button run only on the server. But I can't believe you can't make that simple call. I really hate to use HTML button when the design with ASP on a Web Form is so fast and easy.

Since I am a newbie, some code example will be appreciated.

Briefly, I have an ASP button that I want to call the Javascript function "ButtonClicked"

Thanks

Frag
 
E

Erwin Moller

Frag said:
Hi guys,

I searched around without any clear answer. Tons of stuff, but nothing
concrete.

I am trying to call this Javascript function:

function ButtonClicked()
{
alert("The button has been clicked.");
}

Calling it from an HTML button is no problem at all. But there is no way I
can call that function from an ASP button. I tried from the HTML side or
the aspx side.

I understood that an ASP button run only on the server. But I can't
believe you can't make that simple call. I really hate to use HTML button
when the design with ASP on a Web Form is so fast and easy.

Since I am a newbie, some code example will be appreciated.

Briefly, I have an ASP button that I want to call the Javascript function
"ButtonClicked"

Thanks

Frag

Hi Frag,

I haven't got a clue what an ASP-button is, but if it is some HTML generated
by a tool, just look into the code it produces.
If you see <a href="">blabla</a> that is where you can try to add some
simple code in the anchor, like onClick="".

If the code is always generated dynamically, you should read in the specs
how to add extra things to it (if possible).

Regards,
Erwin Moller
 
K

kaeli

R

Randy Webb

Unregistered said:
Public Sub btnCallJavascript_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCallJavascript.Click

lblScript.Text = "<SCRIPT
language='Javascript1.2'>popUp)
</SCRIPT>"

Why do people continue to use the outdated language attribute? And when
they do use it, they use a buggy version number without knowing the
possible implications of it?

<script language="javascript1.2">
a = 30;
b = 40;
if (a = b){
alert('They are equal')
}
else{
alert('They are not equal')
}
</script>

Test the above in Netscape 4.xx, and then any other browser.
Unregistered -

You really should get a real newsreader and subscribe to
new:comp.lang.javascript and stop using a site that portrays itself as a
"private forum" when it is anything but that.

Its more a joke than anything else.
 
R

Richard Cornford

<script language="javascript1.2">
a = 30;
b = 40;
if (a = b){
alert('They are equal')
}
else{
alert('They are not equal')
}
</script>
Test the above in Netscape 4.xx, and then any other browser.

It might be best not to do the comparison with IceBrowser as it uses the
Rhino javascript engine and the docs for Rhino say it will respect
language="javascript1.2" and use the alternative type-converting rules
(though I have never tested that, not using the language attribute
myself anymore).

It is a bit unfair to use the text "They are equal" when the test you
are performing is an assignment (not comparison), though it adequately
illustrates the problem.

Here are a few comparisons illustrations of the differences:-

<html>
<head>
<title></title>
</head>
<body>
<script language="javascript1.2">
if("40" == 40){
document.write('(&quot;40&quot; == 40) is true.<br>')
}else{
document.write('(&quot;40&quot; == 40) is false.<br>')
}
if(0 == false){
document.write('(0 == false) is true.<br>')
}else{
document.write('(0 == false) is false.<br>')
}
if("" == false){
document.write('(&quot;&quot; == false) is true.<br>')
}else{
document.write('(&quot;&quot; == false) is false.<br>')
}
</script>
</body>
You really should get a real newsreader and subscribe to
new:comp.lang.javascript and stop using a site that portrays
itself as a "private forum" when it is anything but that.

I think that they have abandoned the pretence that they are a private
forum, though they have done little to dray attention to the reality and
are maintaining a number of other deceptions related to that original
one.

But they have also stopped fully reporting comp.lang.javascirpt. So,
with no guarantee that any response made to someone posting from
forum4designers.com will even be seen there, and knowing that any reply
made will be garbled by inappropriate presentation, it is questionable
whether it is worth anyone's effort to compose a worthwhile response to
posts originating on that site.
Its more a joke than anything else.

A bad joke.

Richard.
 
R

Randy Webb

Richard said:
It might be best not to do the comparison with IceBrowser as it uses the
Rhino javascript engine and the docs for Rhino say it will respect
language="javascript1.2" and use the alternative type-converting rules
(though I have never tested that, not using the language attribute
myself anymore).

Just one more reason *not* to use the language attribute.

It is a bit unfair to use the text "They are equal" when the test you
are performing is an assignment (not comparison), though it adequately
illustrates the problem.

In Netscape 4.xx with language="javascript1.2", it does a comparison,
not an assignment. Since they are not equal, it will alert that they are
not equal. In modern browsers then it alerts they are equal because it
can set the assignment, thus its true, so it alerts.

Perhaps:

<script language="javascript1.2">
a = 30;
b = 40;
if (a = b){
alert('I honor it as an assignment')
}
else{
alert('I honor it as a comparison')
}
</script>


Might have been better alerts.

I think that they have abandoned the pretence that they are a private
forum, though they have done little to dray attention to the reality and
are maintaining a number of other deceptions related to that original
one.

I am not so sure they have. They censor out the part of the posts that
we normally quote/complain about. Namely, the generated signature thats
get posted. When viewing the post on the site, you do not see that
section of the post. But they showed my signature line (and yours as well).

http://www.forum4designers.com/message36240.html

Is this very thread, and if you look at the post that I replied to,
there is no signature on it telling where it was posted from nor the
link to the thread.

But they have also stopped fully reporting comp.lang.javascirpt. So,
with no guarantee that any response made to someone posting from
forum4designers.com will even be seen there, and knowing that any reply
made will be garbled by inappropriate presentation, it is questionable
whether it is worth anyone's effort to compose a worthwhile response to
posts originating on that site.

And miss out on all this fun? You are kidding me, right? <g>

Actually, they showed this entire thread (so far anyway). Will be
interesting to see if anything from my post after gets "lost" or not.
 
R

Richard Cornford

In Netscape 4.xx with language="javascript1.2", it does a comparison,
<snip>

You are right it does. How on earth can it decide when it is supposed to
be doing comparison and when it is supposed to be doing assignment? I
use the result of assignment expressions in - if - statements all the
time. In practice it is not very important if the language attribute is
not used at all but given how often I see scripts with version 1.2
language attributes I am surprised we don't see more problems directly
resulting from them (or could that just be the result of limited
testing).

... . But they showed my signature line (and yours as well).

Do they? I don't recall posting with a signature during the period in
which they have been operating.

And miss out on all this fun? You are kidding me, right? <g>
<snip>

I will copy and paste a pre-written standard response. No effort, no
waste if it is not reported, potentially as much fun.

Richard.
 
R

Randy Webb

Richard said:
<snip>

You are right it does. How on earth can it decide when it is supposed to
be doing comparison and when it is supposed to be doing assignment?

Its a bug in the if conditional in javascript1.2 specifically. So it
only shows itself when you do if(something=somethingElse) instead of
if(something==somethingElse). I have never tested it in any other
conditionals (while and for loops).
I use the result of assignment expressions in - if - statements all the
time. In practice it is not very important if the language attribute is
not used at all but given how often I see scripts with version 1.2
language attributes I am surprised we don't see more problems directly
resulting from them (or could that just be the result of limited
testing).

If its inside an if statement, it will do a comparison. Otherwise, it
does as its supposed to do. As far as I know, if (a=b) will always
result in true in modern browsers (the exception would be if a was read
only).
Do they? I don't recall posting with a signature during the period in
which they have been operating.

I am so used to seeing signatures at the bottom, that I mistook your
name for a signature. It shows mine, so its actively censoring what it
appends to the posts.
<snip>

I will copy and paste a pre-written standard response. No effort, no
waste if it is not reported, potentially as much fun.

Post it when you get it written. Maybe we could add a very unique word
so that people could filter it out (much like the FAQ gets filtered by
some), but based on content instead of subject lines. Or better, a
unique phrase "forum4webdesigner's site ........."
 
R

Randy Webb

Lasse said:
[ if (a=b) in JS1.2]
Its a bug in the if conditional in javascript1.2 specifically.


I like to think so too, but I guess it was considered a "feature".
I.e., it was deliberate. Good thing it was stopped in time!

Netscape 4 was enough to drive a teetotaler to drink and an atheist to
religion. Yes, its a very good thing it was stopped :)

.... or if b counts as false.
Try
var a=42;
var b=0;
if (a=b) {} else {alert("b false or JS 1.2 in effect");}

Yikes! Just when I thought I had it figured out, they type convert on
me. Sheesh. I think I will just stick to == and be happy :)
 
R

Richard Cornford

... . As far as I know, if (a=b) will always
result in true in modern browsers ...
<snip>

The evaluated result of an assignment expression is the value assigned:-

var obj;
if(obj = document.getElementById("someID")){
... //only if - obj - is assigned non-null value
}

- so it can type-convert to both true and false.

Richard.
 
L

Lasse Reichstein Nielsen

[ if (a=b) in JS1.2]
Its a bug in the if conditional in javascript1.2 specifically.

I like to think so too, but I guess it was considered a "feature".
I.e., it was deliberate. Good thing it was stopped in time!
As far as I know, if (a=b) will always result in true in modern
browsers (the exception would be if a was read only).

.... or if b counts as false.
Try
var a=42;
var b=0;
if (a=b) {} else {alert("b false or JS 1.2 in effect");}

/L
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top