Javascript alert message problem

T

Tony Girgenti

Hello.

I'm developing and testing a web application using VS.NET 2003, VB, .NET
Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2
computer. I'm using a web form.

Using this line of code works great. It displays a little message box with
the alert message in it.

Me.btnGetArchivedTrips.Attributes.Add("onMouseOver", "alert('mouse over')")

But how do i get it to display the alert message without doing a mouse over,
just trying to put it into an if statement ?

If Calendar1.SelectedDate > Me.Calendar2.SelectedDate) Then
alert('mouse over')")
End If

Thanks,
Tony
 
M

Mark Rae

Using this line of code works great. It displays a little message box
with the alert message in it.

Me.btnGetArchivedTrips.Attributes.Add("onMouseOver", "alert('mouse
over')")

But how do i get it to display the alert message without doing a mouse
over, just trying to put it into an if statement ?

If Calendar1.SelectedDate > Me.Calendar2.SelectedDate) Then
alert('mouse over')")
End If

Er...have you tried

If Calendar1.SelectedDate > Me.Calendar2.SelectedDate) Then
Me.btnGetArchivedTrips.Attributes.Add("onMouseOver", "alert('mouse
over')")
End If
 
T

Tony Girgenti

Hello Mark.

I guess i didn't explain my problem correctly. Within the if statement, i
just want the alert part. In other words if the startdate/enddate compare
is true, i want a little message to pop up that indicates the problem. Like
"Dates are incorrect".

Thanks for your reply.

Tony
 
B

bruce barker \(sqlwork.com\)

if i know vb well enough:

If Calendar1.SelectedDate > Me.Calendar2.SelectedDate) Then
Page.ClientScript.RegisterClientScriptBlock(me.GetType(),"alert","alert('mouse
over');",true)
End If

-- bruce (sqlwork.com)
 
T

Tony Girgenti

Hello Bruce.

This is not working because the IDE is saying "ClientScript is not a member
of System.Web.UI.Page". I can't figure out how to code it so that it is
accepted by the coding syntax.

Thanks,
Tony
 
G

Gaurav Vaish \(www.EdujiniOnline.com\)

Hello Bruce.
This is not working because the IDE is saying "ClientScript is not a
member of System.Web.UI.Page". I can't figure out how to code it so that
it is accepted by the coding syntax.

I think you are using ASP.Net 1.1

Coming to your original problem:
If Calendar1.SelectedDate > Me.Calendar2.SelectedDate) Then
alert('mouse over')")
End If

Solution suggested by Mark is correct way to go about it...

What you are expecting above is:

1. Manipulation of the Data on the server side
2. Alert on the client side

=> Two things happening together is not possible.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://articles.edujinionline.com/webservices
-----------------------------------------
 
T

Tony Girgenti

Hello Gaurav.

I think i understand what you are saying. Correct me if i am wrong. Are
you saying that this part of the statement "If Calendar1.SelectedDate >
Me.Calendar2.SelectedDate Then"
is occurring on the server side, but this part "alert('mouse over')")" is
happening on the client side ?

If that's the case, then how do i go about doing this ? I tried putting it
into the HTML, but i can't get it to execute the function.

Thanks,
Tony

"Gaurav Vaish (www.EdujiniOnline.com)"
 
D

Damien

Tony said:
Hello Bruce.

This is not working because the IDE is saying "ClientScript is not a member
of System.Web.UI.Page". I can't figure out how to code it so that it is
accepted by the coding syntax.

Thanks,
Tony
In 1.1, it would be


Me.RegisterClientScriptBlock("warning","<script>alert('hello');</script>")

Damien
 
G

Gaurav Vaish \(www.EdujiniOnline.com\)

I think i understand what you are saying. Correct me if i am wrong. Are
you saying that this part of the statement "If Calendar1.SelectedDate >
Me.Calendar2.SelectedDate Then"
is occurring on the server side, but this part "alert('mouse over')")" is
happening on the client side ?

If that's the case, then how do i go about doing this ? I tried putting
it into the HTML, but i can't get it to execute the function.

Bingo!
You got it right...

You need to do something like this:

if Calendar1.SelectedDate > Me.Calendar2.SelectedDate Then
Me.Page.RegisterClientScriptBlock("Unique_Name_Like_Calendar1_Error",_
"<script type='text/javascript'
language='javascript'>alert('Error in selected date');</script>")
End if

What this will do is emit this script just before the end of "form"
element... ie, near the end of the page. And will give an alert almost
immediately as the page gets completely loaded.


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://articles.edujinionline.com/webservices
-----------------------------------------
 
T

Tony Girgenti

Wow. That's great. Thanks to you and Damien for your code.

I need to learn more about scripting, but i'm confused about all the
scripting terminology. When i do searches for javascript, i always seem to
get returns that involve VBscript, Jscript, javascript, client-side scripts,
HTML etc.

What is it that i should be looking for ? and should i be looking for a
particular version ? Is what you did for me called "javascript" ?

Also, the second line of the HTML code for my web page is "<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">". Does that mean the HTML
version is 4.0 ?

Any help would be gratefully appreciated.

Thanks again,
Tony

"Gaurav Vaish (www.EdujiniOnline.com)"
 
L

Laurent Bugnion

Hi,

[crossposting removed, reply posted to
microsoft.public.dotnet.framework.aspnet only]

Tony said:
Wow. That's great. Thanks to you and Damien for your code.

I need to learn more about scripting, but i'm confused about all the
scripting terminology. When i do searches for javascript, i always seem to
get returns that involve VBscript, Jscript, javascript, client-side scripts,
HTML etc.

What is it that i should be looking for ? and should i be looking for a
particular version ? Is what you did for me called "javascript" ?

You should be looking for "client-side javascript". JScript is
Microsoft's implementation (running in IE), so there are chances that
these examples also run on Firefox. However, there are differences in
the implementation. ECMAScript is the specification. As for VBScript,
it's Visual Basic Script, quite similar to VBA but running in IE only. I
don't recommend learning it, you can do pretty much everything in
JavaScript anyway, and it's cross browser compatible.

Also, the second line of the HTML code for my web page is "<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">". Does that mean the HTML
version is 4.0 ?

Actually, it's a directive for the browser to select the parser engine.
In that case, it's HTML 4.0 *transitional*, which is a step towards
XHTML. Using this doctype, you won't see many changes with standard HTML
4.0. I would actually recommend XHTML 1.0 transitional, which is a
bigger step towards XHTML, and is very well supported by Visual Studio
(integrated validators). To select the validator you want (which checks
as you type), right click in an ASPX page, select "Formatting and
Validation", and then "Validation". There you can choose the validator
you want to use.
Any help would be gratefully appreciated.

Thanks again,
Tony

HTH,
Laurent
 
T

Tony Girgenti

Hello Laurent.

So i should basically stay with client-side javascript for my learning
purposes.

Also, i don't see the "Formatting and Validation" option on the right-click
menu. I'm using ASP 1.1 and VS.NET 2003. Should i see it there ?

Thanks,
Tony

Laurent Bugnion said:
Hi,

[crossposting removed, reply posted to
microsoft.public.dotnet.framework.aspnet only]

Tony said:
Wow. That's great. Thanks to you and Damien for your code.

I need to learn more about scripting, but i'm confused about all the
scripting terminology. When i do searches for javascript, i always seem
to get returns that involve VBscript, Jscript, javascript, client-side
scripts, HTML etc.

What is it that i should be looking for ? and should i be looking for a
particular version ? Is what you did for me called "javascript" ?

You should be looking for "client-side javascript". JScript is Microsoft's
implementation (running in IE), so there are chances that these examples
also run on Firefox. However, there are differences in the implementation.
ECMAScript is the specification. As for VBScript, it's Visual Basic
Script, quite similar to VBA but running in IE only. I don't recommend
learning it, you can do pretty much everything in JavaScript anyway, and
it's cross browser compatible.

Also, the second line of the HTML code for my web page is "<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">". Does that mean the
HTML version is 4.0 ?

Actually, it's a directive for the browser to select the parser engine. In
that case, it's HTML 4.0 *transitional*, which is a step towards XHTML.
Using this doctype, you won't see many changes with standard HTML 4.0. I
would actually recommend XHTML 1.0 transitional, which is a bigger step
towards XHTML, and is very well supported by Visual Studio (integrated
validators). To select the validator you want (which checks as you type),
right click in an ASPX page, select "Formatting and Validation", and then
"Validation". There you can choose the validator you want to use.
Any help would be gratefully appreciated.

Thanks again,
Tony

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
G

Gaurav Vaish \(www.EdujiniOnline.com\)

Hi Tony,
I need to learn more about scripting, but i'm confused about all the
scripting terminology. When i do searches for javascript, i always seem
to get returns that involve VBscript, Jscript, javascript, client-side
scripts, HTML etc.

Forget all about VBScript, JScript... if you are looking to work with
them on client side -- you are tied to IE. Firefox is the recipe-of-the-day.
What is it that i should be looking for ? and should i be looking for a
particular version ? Is what you did for me called "javascript" ?

If I recall correctly, Javascript 1.6 is the latest... albeit 1.2+
should be good enough for quite a few practical purposes.
Also, the second line of the HTML code for my web page is "<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">". Does that mean the HTML
version is 4.0 ?

HTML 4.0 "Transitional" meaning that somethings like "<br>", "<img>" etc
will go without warnings where in XHTML mode it has to be "<br />", "<img
.... />".

I would suggest you to have a look into the topic of "XML", "DTD" and
"XSD" and then also look into "HTML" and "its DTD".

For advanced processing on client-side, additional topics would be
Javascript, DOM Level 3 API.

All of this is available on www.w3.org. This spectrum will give you a
complete understanding of the "web applications", how they function, what
all things you should take care of / note of etc when designing the "server
side" and the "client side" of your application.
Any help would be gratefully appreciated.

Hope that helps!
Thanks again,

Most welcome!


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://eduzine.edujinionline.com
-----------------------------------------
 
L

Laurent Bugnion

Hi,

Tony said:
Hello Laurent.

So i should basically stay with client-side javascript for my learning
purposes.

That's my recommendation, yes.

Also, the official JavaScript newsgroup is comp.lang.javascript, which
especially (but not exclusively) deals with client-side javascript
related questions.

Also, i don't see the "Formatting and Validation" option on the right-click
menu. I'm using ASP 1.1 and VS.NET 2003. Should i see it there ?

Unfortunately, no. It's a new feature in VS2005 (amongst many other
improvements)
Thanks,
Tony

My pleasure,
Laurent
 
L

Laurent Bugnion

Hi,
Forget all about VBScript, JScript... if you are looking to work with
them on client side -- you are tied to IE. Firefox is the recipe-of-the-day.

Firefox still represents a minority of the browsers, and with the
release of IE7, I think it will worsen Firefox's ratings. I personally
like Firefox (mostly for tabbed browsing), but that will be available in
IE too.

Anyway, I will always recommend writing standard JavaScript, so that it
works reasonably in all newer browsers. This is possible without major
efforts, once you mastered the learning curve. JavaScript and the DOM
are now standard enough that this shouldn't cause big problems. In that
sense, I find reasonable to recommend JavaScript (i.e. Netscape's
implementation) and JScript (i.e Microsoft's implementation), which are
anyway almost the same.

Also, using feature detection instead of browser detection is alwaysa
good idea to increase compatibility, and degrade gracefully when a
feature is not available.

if ( document.getElementById )
{
document.getElementById( "myId" ).value = "...";
}
else
{
// Inform user or use another way.
}

HTH,
Laurent
 
T

Tony Girgenti

Thanks to Gaurav and Laurent for their replies. I have a lot of learning to
do.

Tony
 
T

Tony Girgenti

Gaurav.

One thing i don't understand is "Forget all about VBScript, JScript". If
JScript is Microsoft's implementation of JavaScript and i am using VS.NET
2003, then why not use JScript ?

I'm sure you have a good reason, but i am puzzled by that.

Thanks,
Tony

"Gaurav Vaish (www.EdujiniOnline.com)"
 
L

Laurent Bugnion

Hi,

Tony said:
Gaurav.

One thing i don't understand is "Forget all about VBScript, JScript". If
JScript is Microsoft's implementation of JavaScript and i am using VS.NET
2003, then why not use JScript ?

I'm sure you have a good reason, but i am puzzled by that.

Thanks,
Tony

I agree. See my post in the same thread. Better learn and program
against standards, instead of concentrating on one browser only,
whichever that is.

HTH,
Laurent
 
G

Gaurav Vaish \(www.EdujiniOnline.com\)

I agree. See my post in the same thread. Better learn and program against
standards, instead of concentrating on one browser only, whichever that
is.

Laurent said it all... reach out to as many people as you can.
"Why not bother" about millions of users that work with Firefox, or Safari
(kinda defacto on Mac from Tiger onwards). Note that MSIE does not work
identically on Windows and Mac.



--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://eduzine.edujinionline.com
-----------------------------------------
 
G

Gaurav Vaish \(www.EdujiniOnline.com\)

Firefox still represents a minority of the browsers, and with the release
of IE7, I think it will worsen Firefox's ratings. I personally like
Firefox (mostly for tabbed browsing), but that will be available in IE
too.

Two things:
1. I still won't leave that "millions of users" audience
2. Firefox is anyway more secure as compared to IE. Well, at least I have
more faith in it :)


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://eduzine.edujinionline.com
-----------------------------------------
 

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
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top