I recently attempted to make my client code object oriented and in seperate files. but it ended up causing more problems then it helped. Has anyone else attempted this approach with ASP.NET? Is there anyone who has had success with this approach? I am not
talking about writing custom controls but about a business solution.
Visit my blog at:
http://startingdotneprogramming.blogspot.com
you should some more information and specify the problem you're facing. To use OOP concepts in ASP.NET works well (you can create all aspects/layers in an OOP style), but I would personally not try to bring these concepts to JavaScript (because it is not
a real OOP language and it will complicate things more than it help).
Regards.
If my post solves your problem, please mark as answer.
I am looking for best practices in the future. I dont have any examples because the code was taken out.
I ran into the following issues:
Since the javascript was in a seperate file getting the client id was tricky. I had to register them as startup scripts or include a script that registered them. This wasnt as straight forward as just doing inline scripts and using the expressions <%= MyControl.ClientID
%>
Javascript doesnt have a well designed class syntax.
The script was larger and when I made a mistake it didnt correct me like it would in C# or VB.NET. I had to run in to see if it was correct. The extra clunkyness of the OO syntax was harder for me to proof then simple procedural scripts.
ASP.NET controls and 3rd party controls were not designed to call a function in a class. It was hard to find the correct examples becuase they are usually geared for non OO client scripts.
Visit my blog at:
http://startingdotneprogramming.blogspot.com
Since the javascript was in a seperate file getting the client id was tricky. I had to register them as startup scripts or include a script that registered them. This wasnt as straight forward as just doing inline scripts and using the expressions <%= MyControl.ClientID
%>
To register them as startup scripts is a common solution. I know it can be tricky to handle JavaScript files from code-behind.
KenParkerJr
Javascript doesnt have a well designed class syntax
Again JavaScript is not an OOP language. You can apply OOP concepts to JavaScript, but normally you wouldn't do that, because things can become complicated (the reason is that JavaScript originally wasn't designed for this purpose).
KenParkerJr
The script was larger and when I made a mistake it didnt correct me like it would in C# or VB.NET. I had to run in to see if it was correct. The extra clunkyness of the OO syntax was harder for me to proof then simple procedural scripts.
I think you're talking about IntelliSense?! That's a normal thing. The support for JavaScript has become a lot better, but because it is a scripting language and you normally don't have IntelliSense you have to know what you're doing.
If your files or scripts are to big try to separate them into logical pieces (functions or files) like you would do in C#.
KenParkerJr
ASP.NET controls and 3rd party controls were not designed to call a function in a class. It was hard to find the correct examples becuase they are usually geared for non OO client scripts.
That's similar to point two. In my (personal) opinion you should avoid to call JavaScript (client) code from code-behind (server). If you have something like this you should think twice if you really need that.
Regards.
If my post solves your problem, please mark as answer.
Marked as answer by kenparkerjr on Mar 21, 2012 04:10 PM
That's similar to point two. In my (personal) opinion you should avoid to call JavaScript (client) code from code-behind (server). If you have something like this you should think twice if you really need that.
I am primarly talking about ASP.NET AJAX server controls like ASP:Validator that are expecting a procedural javascript function and not a function inside of a class. Even though it may be supported, documentation always assumes you are using simple procedures
and not class based client scripting.
So my real question is: Is it worth it for business solutions to do OO client scripting or is it better to just use non-OO client scripting. Frameworks I think it is definatly worth it.
Visit my blog at:
http://startingdotneprogramming.blogspot.com
Is it worth it for business solutions to do OO client scripting
Sure and especially from the standpoint of using a library to help organize our JS. Interesting thing about this thread is that I think you like a lot of us has done very well with organization of code via OO principals and good design practices on the
managed code side of things, but our JS scripts have become these monolithic beasts that are out of control.
Have you looked into Knockout.js or backbone.js? I went to hear John Papa speak about this at the last VSLive! conference and it seemed like a great way to organize and reduce the amount of JS required and helped with databinding as well. Here
is a quote from the link below describing it: "Knockoutjs helps you build Object Oriented, MVVM-style Javascript code by focusing on declarative bindings, automatic UI refresh, dependency tracking, and templating."
And for the record, even know it is sometimes debated, JavaScript isconsidered a language that supports Object Oriented Programming. It is somewhat subjective since there is no definitive authority on decalring OO languages, but it's characteristics do show it to be considered so. From Wikipedia: "JavaScript is a prototype-based
scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented,[5] imperative, and functional[1][6] programming styles."
For a very long conversation on this and to learn why it is considered to be, have a look at the following:
you like a lot of us has done very well with organization of code via OO principals and good design practices on the
managed code side of things, but our JS scripts have become these monolithic beasts that are out of control.
This is exactly what I want to avoid. I believe in a quality solution and procedural javascript can get unmaintainable fast.
atconway
ave you looked into Knockout.js or backbone.js?
I have been reading on them but I have not yet used them in a project.
atconway
"Knockoutjs helps you build Object Oriented, MVVM-style Javascript code
They beat me to it! I was trying to impliment that using js. My friends thought I was nuts. But it sounds like it is viable.
My problem was that ASP.NET Serverside code using MVVM was just impractical because if you wanted to do code on the client side it blew away your pattern. I thought it would be best to put the MVVM on the client side and have it call webservices/methods.
This means goodbye to most of the ASP.NET controls however.
atconway
And for the record, even know it is sometimes debated, JavaScript isconsidered a language that supports Object Oriented Programming
Yes, I agree. I just dont think it does it very well. It was an attempt to not overcomplicate things. Alot of things like namespaces are supported thru using other features in a diffrent way. Declare an object and use it like a namespace. but thats a diffrent
topic.
Visit my blog at:
http://startingdotneprogramming.blogspot.com
KenParkerJr
Participant
1081 Points
270 Posts
Javascript OO scripts
Mar 16, 2012 07:12 PM|LINK
I recently attempted to make my client code object oriented and in seperate files. but it ended up causing more problems then it helped. Has anyone else attempted this approach with ASP.NET? Is there anyone who has had success with this approach? I am not talking about writing custom controls but about a business solution.
http://startingdotneprogramming.blogspot.com
Horizon_Net
Star
8277 Points
1435 Posts
Re: Javascript OO scripts
Mar 16, 2012 09:31 PM|LINK
Hi,
you should some more information and specify the problem you're facing. To use OOP concepts in ASP.NET works well (you can create all aspects/layers in an OOP style), but I would personally not try to bring these concepts to JavaScript (because it is not a real OOP language and it will complicate things more than it help).
If my post solves your problem, please mark as answer.
KenParkerJr
Participant
1081 Points
270 Posts
Re: Javascript OO scripts
Mar 16, 2012 09:40 PM|LINK
I am looking for best practices in the future. I dont have any examples because the code was taken out.
I ran into the following issues:
http://startingdotneprogramming.blogspot.com
Horizon_Net
Star
8277 Points
1435 Posts
Re: Javascript OO scripts
Mar 17, 2012 01:20 AM|LINK
To register them as startup scripts is a common solution. I know it can be tricky to handle JavaScript files from code-behind.
Again JavaScript is not an OOP language. You can apply OOP concepts to JavaScript, but normally you wouldn't do that, because things can become complicated (the reason is that JavaScript originally wasn't designed for this purpose).
I think you're talking about IntelliSense?! That's a normal thing. The support for JavaScript has become a lot better, but because it is a scripting language and you normally don't have IntelliSense you have to know what you're doing.
If your files or scripts are to big try to separate them into logical pieces (functions or files) like you would do in C#.
That's similar to point two. In my (personal) opinion you should avoid to call JavaScript (client) code from code-behind (server). If you have something like this you should think twice if you really need that.
If my post solves your problem, please mark as answer.
KenParkerJr
Participant
1081 Points
270 Posts
Re: Javascript OO scripts
Mar 21, 2012 03:31 PM|LINK
I am primarly talking about ASP.NET AJAX server controls like ASP:Validator that are expecting a procedural javascript function and not a function inside of a class. Even though it may be supported, documentation always assumes you are using simple procedures and not class based client scripting.
So my real question is: Is it worth it for business solutions to do OO client scripting or is it better to just use non-OO client scripting. Frameworks I think it is definatly worth it.
http://startingdotneprogramming.blogspot.com
atconway
All-Star
16846 Points
2756 Posts
Re: Javascript OO scripts
Mar 21, 2012 03:55 PM|LINK
Sure and especially from the standpoint of using a library to help organize our JS. Interesting thing about this thread is that I think you like a lot of us has done very well with organization of code via OO principals and good design practices on the managed code side of things, but our JS scripts have become these monolithic beasts that are out of control.
Have you looked into Knockout.js or backbone.js? I went to hear John Papa speak about this at the last VSLive! conference and it seemed like a great way to organize and reduce the amount of JS required and helped with databinding as well. Here is a quote from the link below describing it: "Knockoutjs helps you build Object Oriented, MVVM-style Javascript code by focusing on declarative bindings, automatic UI refresh, dependency tracking, and templating."
Knock out that JS with knockoutjs:
http://www.jstawski.com/archive/2011/05/27/knock-out-that-js-with-knockoutjs.aspx
Knockout JS: Helping you build dynamic JavaScript UIs with MVVM and ASP.NET:
http://channel9.msdn.com/events/MIX/MIX11/FRM08
Knockoutjs:
http://knockoutjs.com/
And for the record, even know it is sometimes debated, JavaScript is considered a language that supports Object Oriented Programming. It is somewhat subjective since there is no definitive authority on decalring OO languages, but it's characteristics do show it to be considered so. From Wikipedia: "JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented,[5] imperative, and functional[1][6] programming styles."
For a very long conversation on this and to learn why it is considered to be, have a look at the following:
Is JavaScript object-oriented?
KenParkerJr
Participant
1081 Points
270 Posts
Re: Javascript OO scripts
Mar 21, 2012 04:06 PM|LINK
This is exactly what I want to avoid. I believe in a quality solution and procedural javascript can get unmaintainable fast.
I have been reading on them but I have not yet used them in a project.
They beat me to it! I was trying to impliment that using js. My friends thought I was nuts. But it sounds like it is viable.
My problem was that ASP.NET Serverside code using MVVM was just impractical because if you wanted to do code on the client side it blew away your pattern. I thought it would be best to put the MVVM on the client side and have it call webservices/methods. This means goodbye to most of the ASP.NET controls however.
Yes, I agree. I just dont think it does it very well. It was an attempt to not overcomplicate things. Alot of things like namespaces are supported thru using other features in a diffrent way. Declare an object and use it like a namespace. but thats a diffrent topic.
http://startingdotneprogramming.blogspot.com
KenParkerJr
Participant
1081 Points
270 Posts
Re: Javascript OO scripts
Mar 21, 2012 04:10 PM|LINK
Great discussion guys!
http://startingdotneprogramming.blogspot.com