By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Very simple question on Javascript with ASP button

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Frag wrote:
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

Jul 20 '05 #2

P: n/a
In article <eC**********@fe09.usenetserver.com>, fr**@frag.com
enlightened us with...

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.


Sure you can.
Attach the script to it.

http://dotnetextreme.com/articles/validationAspNet.asp
http://www.code101.com/Code101/Displ...le.aspx?cid=33

Questions about dotnet best directed to
msnews:microsoft.public.dotnet.scripting.

Oh, and I don't use dotnet. I found the answer on Google in about a
minute. Google is your friend.

--
--
~kaeli~
If a book about failures doesn't sell, is it a success?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3

P: n/a

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

End Su

Unregistered
-----------------------------------------------------------------------
Posted via http://www.forum4designers.co
-----------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message36240.htm

Jul 20 '05 #4

P: n/a
Unregistered wrote:
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.

End Sub
Unregistered -
------------------------------------------------------------------------
Posted via http://www.forum4designers.com
------------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message36240.html


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.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5

P: n/a
"Randy Webb" <hi************@aol.com> wrote in message
news:Wq********************@comcast.com...
<snip>
<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>
</html>
Posted via http://www.forum4designers.com

<snip>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.
Jul 20 '05 #6

P: n/a
Richard Cornford wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:Wq********************@comcast.com...
<snip>
<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).


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.

<--snip-->
Posted via http://www.forum4designers.com


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


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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7

P: n/a
"Randy Webb" <hi************@aol.com> wrote in message
news:et********************@comcast.com...
<snip>
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).

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

<snip>
... , 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>

<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.
Jul 20 '05 #8

P: n/a
Richard Cornford wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:et********************@comcast.com...
<snip>
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?


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).
<snip>
... . 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.


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


<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 ........."
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9

P: n/a
"Randy Webb" <hi************@aol.com> wrote in message
news:8P********************@comcast.com...
<snip>
... . 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.
Jul 20 '05 #10

P: n/a
Randy Webb <hi************@aol.com> writes:

[ 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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #11

P: n/a
Lasse Reichstein Nielsen wrote:
Randy Webb <hi************@aol.com> writes:

[ 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 :)

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");}


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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.