473,395 Members | 1,623 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,395 software developers and data experts.

What's the REAL deal with Javascript ?

Liz
Do you really have to use these methods like RegisterClientScriptBlock() to
get client-side Javascript into an ASP.NET 2.0 page ? For anything beyond
trivial scripting, this is really a painful process, no ?

I guess I'm not clear why you can't put JS inline ? Doesn't it just get
emitted along with any literal HTML in your page ??

Is there a way to load an external xxx.js file into your code ?

Thanks for any input ...

Liz
Oct 7 '06 #1
13 1277
you can use all the normal js stuff...
"Liz" <li*@tiredofspam.comwrote in message news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like RegisterClientScriptBlock() to
get client-side Javascript into an ASP.NET 2.0 page ? For anything beyond
trivial scripting, this is really a painful process, no ?

I guess I'm not clear why you can't put JS inline ? Doesn't it just get
emitted along with any literal HTML in your page ??

Is there a way to load an external xxx.js file into your code ?

Thanks for any input ...

Liz


Oct 7 '06 #2
Liz

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:OJ**************@TK2MSFTNGP03.phx.gbl...
you can use all the normal js stuff...
really ? so what's with the Page methods like "RegisterClientScriptBlock()"
?

L
"Liz" <li*@tiredofspam.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like RegisterClientScriptBlock()
to
get client-side Javascript into an ASP.NET 2.0 page ? For anything
beyond
trivial scripting, this is really a painful process, no ?

I guess I'm not clear why you can't put JS inline ? Doesn't it just get
emitted along with any literal HTML in your page ??

Is there a way to load an external xxx.js file into your code ?

Thanks for any input ...

Liz


Oct 7 '06 #3
"Liz" <li*@tiredofspam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:OJ**************@TK2MSFTNGP03.phx.gbl...
>you can use all the normal js stuff...

really ?
Yes.
so what's with the Page methods like "RegisterClientScriptBlock()"
It allows you to create dynamic JavaScript.
Oct 7 '06 #4

"Liz" <li*@tiredofspam.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like RegisterClientScriptBlock()
to
get client-side Javascript into an ASP.NET 2.0 page ? For anything beyond
trivial scripting, this is really a painful process, no ?
No, you do not HAVE to do anything. You can write code that does a lot of
things without having any emission of code. The issues comes when you start
working with server controls, as you either have to render, find the name
and write the script (or) emit to get the rendered name of the control.
I guess I'm not clear why you can't put JS inline ? Doesn't it just get
emitted along with any literal HTML in your page ??
Yes. It is largely for naming of controls without having to worry about
where they are on the page.
Is there a way to load an external xxx.js file into your code ?
Yes, you can link it in the HTML.

If you write your routines so they take the control as a parameter and then
emit the control specific calls, you end up with the best of both worlds.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/

*************************************************
Think Outside the Box!
*************************************************
Oct 7 '06 #5
Liz

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:Os**************@TK2MSFTNGP03.phx.gbl...
>
"Liz" <li*@tiredofspam.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like RegisterClientScriptBlock()
to
get client-side Javascript into an ASP.NET 2.0 page ? For anything
beyond
trivial scripting, this is really a painful process, no ?

No, you do not HAVE to do anything. You can write code that does a lot of
things without having any emission of code. The issues comes when you
start
working with server controls,
ok ... so if I have a Grid and I want to swap CSS styles on rows when
onmouseover fires, what then ? I can't just delegate to a method in the
attribute because it'll run on the server ... is there a pattern to do this
on the client ?

L
Oct 7 '06 #6
for a grid, you could add an event handler....

'************************************************* ******
Sub ReportGrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
'
' The ReportGrid_ItemDataBound helper method is used to
' highlight rows in grid table from mouse actions
'
'************************************************* ******

If e.Item.ItemType = ListItemType.Item or e.Item.ItemType = ListItemType.AlternatingItem Then

If e.Item.ItemType = ListItemType.Item Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
'---------------------------------------------------
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='White'")
End If

If e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
'---------------------------------------------------
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='CornSilk'")
End If

'We can add the onclick event handler
e.Item.Attributes.Add("onclick","this.style.backgr oundColor='lightblue'")
End If

End Sub


"Liz" <li*@tiredofspam.comwrote in message news:u6**************@TK2MSFTNGP05.phx.gbl...
>
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:Os**************@TK2MSFTNGP03.phx.gbl...
>>
"Liz" <li*@tiredofspam.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like RegisterClientScriptBlock()
to
get client-side Javascript into an ASP.NET 2.0 page ? For anything
beyond
trivial scripting, this is really a painful process, no ?

No, you do not HAVE to do anything. You can write code that does a lot of
things without having any emission of code. The issues comes when you
start
>working with server controls,

ok ... so if I have a Grid and I want to swap CSS styles on rows when
onmouseover fires, what then ? I can't just delegate to a method in the
attribute because it'll run on the server ... is there a pattern to do this
on the client ?

L


Oct 7 '06 #7
Liz

cool ... thanks :)

Liz
:: but wouldn't it have been easier/nicer if MS had opened up the server tag
attributes spec a bit so you could do something like:

<asp:Control runat="server" client::onmouseover="abc"
client::onmouseout="xyz" ... / ... or some such thing ... ?

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:eh**************@TK2MSFTNGP04.phx.gbl...
for a grid, you could add an event handler....

'************************************************* ******
Sub ReportGrid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
'
' The ReportGrid_ItemDataBound helper method is used to
' highlight rows in grid table from mouse actions
'
'************************************************* ******

If e.Item.ItemType = ListItemType.Item or e.Item.ItemType =
ListItemType.AlternatingItem Then
>
If e.Item.ItemType = ListItemType.Item Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
'---------------------------------------------------
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='White'")
End If

If e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
'---------------------------------------------------
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='CornSilk'")
End If

'We can add the onclick event handler
e.Item.Attributes.Add("onclick","this.style.backgr oundColor='lightblue'")
End If

End Sub


"Liz" <li*@tiredofspam.comwrote in message
news:u6**************@TK2MSFTNGP05.phx.gbl...

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote
in
message news:Os**************@TK2MSFTNGP03.phx.gbl...
>
"Liz" <li*@tiredofspam.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
Do you really have to use these methods like
RegisterClientScriptBlock()
to
get client-side Javascript into an ASP.NET 2.0 page ? For anything
beyond
trivial scripting, this is really a painful process, no ?

No, you do not HAVE to do anything. You can write code that does a lot
of
things without having any emission of code. The issues comes when you
start
working with server controls,
ok ... so if I have a Grid and I want to swap CSS styles on rows when
onmouseover fires, what then ? I can't just delegate to a method in the
attribute because it'll run on the server ... is there a pattern to do
this
on the client ?

L


Oct 7 '06 #8
Hi,

Liz wrote:
cool ... thanks :)

Liz
:: but wouldn't it have been easier/nicer if MS had opened up the server tag
attributes spec a bit so you could do something like:

<asp:Control runat="server" client::onmouseover="abc"
client::onmouseout="xyz" ... / ... or some such thing ... ?
They did.

<asp:ListBox Runat="server"
ID="lsbWhichTreeview"
AutoPostBack="True"
onchange="alert('Test');">

....

</asp:ListBox>

generates this client side code:

<select size="4" name="lsbWhichTreeview"
onchange="alert('Test');setTimeout('__doPostBack(\ 'lsbWhichTreeview\',\'\')',
0)" language="javascript" id="lsbWhichTreeview">

....

</select>

Note the inclusion of the client-side code before the "__doPostBack"
code. I rather recommend against this way, because it worsens the code
readibility. I prefer to do that in the code behind, using the
"Attributes" collection.

I usually add JavaScript to my HTML ages or custom controls using
JavaScript files (always recommended, better encapsulation, easier to
debug, etc...). In the code behind, I use the Attributes collection to
set the event handlers. And I use the ClientScript manager only for
dynamic JavaScript code, which is usually limited to setting "constants"
(JavaScript doesn't have them, I use normal variables for that), and for
localization (setting strings that I get from the resource files).

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
Oct 8 '06 #9
"Laurent Bugnion, GalaSoft" <ga*********@bluewin.chwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
which is usually limited to setting "constants" (JavaScript doesn't have
them, I use normal variables for that)
http://developer.mozilla.org/en/docs...atements:const
Oct 8 '06 #10
Hi,

Mark Rae wrote:
"Laurent Bugnion, GalaSoft" <ga*********@bluewin.chwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...

>>which is usually limited to setting "constants" (JavaScript doesn't have
them, I use normal variables for that)


http://developer.mozilla.org/en/docs...atements:const
The same page also states

"const is a Mozilla-specific extension, it is not supported by IE or Opera."

But I agree that I should have been more precise.

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
Oct 8 '06 #11
Liz

"Laurent Bugnion, GalaSoft" <ga*********@bluewin.chwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
>:: but wouldn't it have been easier/nicer if MS had opened up the server
tag
attributes spec a bit so you could do something like:

<asp:Control runat="server" client::onmouseover="abc"
client::onmouseout="xyz" ... / ... or some such thing ... ?

They did.

<asp:ListBox Runat="server"
ID="lsbWhichTreeview"
AutoPostBack="True"
onchange="alert('Test');">

it's limited ... basically to events where server-side processing might make
sense .... you don't see a mouseover event for ListBox, right ?
Oct 8 '06 #12
Hi,

Liz wrote:
"Laurent Bugnion, GalaSoft" <ga*********@bluewin.chwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...

>>>:: but wouldn't it have been easier/nicer if MS had opened up the server
tag
attributes spec a bit so you could do something like:

<asp:Control runat="server" client::onmouseover="abc"
client::onmouseout="xyz" ... / ... or some such thing ... ?

They did.

<asp:ListBox Runat="server"
ID="lsbWhichTreeview"
AutoPostBack="True"
onchange="alert('Test');">

it's limited ... basically to events where server-side processing might make
sense .... you don't see a mouseover event for ListBox, right ?
One more reason to use the Attributes collection instead. Honestly, in
all my years of ASP.NET programming, I never once added a client-side
event handler to an ASP.NET control tag.

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
Oct 8 '06 #13
"Laurent Bugnion, GalaSoft" <ga*********@bluewin.chwrote in message
news:Od**************@TK2MSFTNGP05.phx.gbl...
One more reason to use the Attributes collection instead. Honestly, in all
my years of ASP.NET programming, I never once added a client-side event
handler to an ASP.NET control tag.
Me neither.
Oct 9 '06 #14

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

Similar topics

9
by: Nick Mudge | last post by:
I am sorry to be a little off topic here, but can someone describe what XML is? I know it is programming languague, but what is the deal with it?
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
6
by: Ricky | last post by:
My question: If I have a mapped driver letter g: that referes to \\servername\d\foldername How do I get java to convert it from g: to the real path so I can use it? I have a script that...
10
by: G Matthew J | last post by:
interesting "signal vs. noise" blog entry: http://37signals.com/svn/archives2/whats_wrong_with_ajax.php
8
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.