jQuery and ASP.NET advantages - asp.net

I am so confused that I thought to ask you for your opinion.
I have written few jquery code with asp.net. But there is group of developer in my company who think that javascript/jquery can be turned off and is insecure
if javascript is insecure, why to use it at the first place
what are the advantages of using jquery with asp.net apart from cross-browser. why not use javascript?
should i use jquery in my asp.net applications?
There were a few posts over here that contained similar question, but not even one that contained good explanation. Please share your thoughts.

if javascript is insecure, why to use it at the first place
To provide advanced browsing experience to those who have it on.
what are the advantages of using jquery with asp.net apart from cross-browser. why not use javascript?
Rapid development. If you're not comfortable with jQuery, code in JavaScript directly, see no problem here.
should i use jquery in my asp.net applications?
That's up to you to decide. Give it a try and see if you'll like it.

• what are the advantages of using jquery with asp.net apart from cross-browser.
why not use javascript?
jQuery is javascript. The purpose of javascript is to enhance the user's browser experience. If this is something you want to include in your website then I would advise you use it. If you do opt to use it, depending on what your requirements are, jQuery would be the best option.

Javascript is no less secure than using the Internet. I would definitely recommend it for the sheer purpose of enhancing the user experience. However, it is also important to make sure your application functions properly with Javascript disabled.
How you write your Javascript is up to you. I use jQuery because I am much more productive with it, primarily because I don't waste time dealing with the inherent short-comings of Javascript, as well as the numerous cross-browser oddities. jQuery is, in fact, Javascript, by the way.

Javascript is not insecure per se -- but you can certainly create insecure code with it, if you're not careful. All code that is 'critical' security-wise should be run in the server, not in the user's browser, because it can be turned off.

To provide a better experience for the users. People today expect web pages to be interactive. The idea of having a totally static site died a while ago. It should also be said, that if someone is really skilled at compromising systems, whether you use JavaScript or not is inconsequential. With cross site scripting attacks etc. someone can embed JavaScript into your site. Using JavaScript might make it easier to compromise a page, but not using, doesn't mean that it is fool proof protection against it.
JQuery is a JavaScript framework, and it abstracts a lot of the necessities from knowing the ins and outs of JavaScript and cross browser support. It also abstracts a lot about what you need to know when manipulating the DOM, which can be extremely frustrating at times. It makes development a lot easier unless you really know what you are doing, and then it still makes development easier in a lot of cases.
I would recommend using some sort of a framework unless you are really good with JavaScript. Jquery may not be the way to go for you, but it is a good one to use. There are others like Prototype and YUI.

Related

Do I need AJAX and ASP.NET for what I'm doing?

Easy question. I used to develop websites back in the days of "classic" ASP, and when I'm asked to do a quick and dirty website for family or friends now, I still resort to direct HTML/ASP and some basic CSS and Javascript - I can get the sites up pretty quickly this way. However, I've had a few requests to design and develop some sites for pay, and thought I should catch up on my web skills. I have been using .NET 3.5, XAML/WPF, etc. for Windows apps, so I'm up on .NET, I'm just behind on the web end.
To the question: If I want to design/code a site that looks identical on all (at least somewhat recent) browsers and platforms, should I be using ASP.NET and AJAX? There might be a little database activity on the site, but not much, so I don't need an enterprise level, multi-tier extendable architecture... just something that looks good and works on multiple platforms without having to code all variations for each browser. After looking at all the ASP.NET books at the bookstore, it seems they all focus mostly on data and postback stuff. Is it still a legit option to use some basic, boring html and javascript with some Flash embedded where needed?
Let me know if I need to clarify the question. Thanks for your advice in advance!
Your question is more loaded than you think, but let me try to address a few points that I think are relevant.
First, how a site looks is almost completely dependent on the HTML/CSS you use and how you code the front end of the site and only slightly dependent on the server technology. So if you want your site to function across browsers and platforms, learn to code following web standards, with semantic markup. (Search on those terms for more info).
Also, ASP.NET comes in two flavors now: ASP.NET MVC and normal ASP.NET. I highly recommend, if you are going to get into ASP.NET, that you follow the MVC platform. It closely follows similar technologies (like Ruby on Rails) and will make the transition to other MVC platforms easier on you. Also, the MVC platform doesn't try to output as much pre-made HTML as straight ASP.NET will when you use their "drag and drop" controls.
Secondly, it really depends on the sites you are building, but straight JS (or JS + jQuery), CSS, and HTML -- and please don't use Flash unless you are embedding a video -- will actually work for a number of basic sites. If you need some things to happen on the server, PHP makes for a great platform. If you are working with advanced database access, and program flow, and since you are already familiar with .NET, then stick with it... MS has some great tools and resources to help you out.
Finally, a lot of developers use a favorite CMS or blogging platform as the backend of simple sites that still need the ability to manage the content easily. Expression Engine (CMS) and WordPress (Blog/Lite-CMS) are often used (both PHP based) but there are tons out there.
Good luck stepping up your game!
I would recommend learning jQuery. This will give you a browser independent abstraction for your JavaScript.
ASP.NET controls will render it's controls in a browser independent way, but that doesn't mean your site will automagically be browser independent. You still need to know how elements are rendered differently in different browsers.
I'd also recommend using a CSS Reset sheet as a starting point for your CSS.
All in all, if you've been developing old school ASP, you'll probably really love ASP.NET as it will save you a lot of time and looping. You may want to jump right in to ASP.NET MVC too.
To the root of your question, I'd learn ASP.NET if you're doing anything more than a simple brochure site. If you have .NET experience, and classic web development experience, then learning ASP.NET is not going to be a big hurdle and will be well worth the effort.
I agree with Aaron Daniels' answer about learning jQuery. jQuery helps a lot with cross-browser compatibility in JavaScript and some CSS-based effects.
However, you should also look into ensuring your site uses well-formed, valid HTML, and doesn't use too many CSS 2+ features. This should ensure that your site is standards compliant, which will mean it will play well with Firefox, Safari, Opera, and even later versions of IE to an extent. You will still need to do manual tweaking for IE - it's been too broken for too long for MS to be able to fix it properly in one go - so look into conditional comments for applying a separate stylesheet for IE users.
AJAX is a handy technology for "desktopifying" your web app. It provides a mechanism for asynchronous callbacks to the web server, so you can pass data to and fro without reloading the page in the browser window. This is how the voting buttons work on StackOverflow, for example.
Lastly, ASP.NET doesn't really have much effect on the end user's experience in terms of the look and feel of the site. It is a server technology that provides for writing complex applications to be delivered over the web to a browser. Having said that, MS have put in some extra goodies to make working with AJAX a little easier.
Hope that helps!

Good resources for cross browser ASP.NET website development

Does anyone know of any good resources for learning about cross-browser development in ASP.NET? Specifically, what causes a page to look different in FF/Chrome/IE, what are the gotchas when developing, how can this issue be addressed in a new project etc.
A good tool for cross-browser websites is Microsofts SuperPreview. This is still in beta, but so far looks like it will be a great help with web development.
Hope that helps!
There's really not a specific resource I've found for that type of information. Generally I've found the information as I encounter the errors. But the first step is learning at least a high level overview of the rendering engines used by the different browsers. They all have their own particular "quirks", thus why a site like http://www.quirksmode.org/ exists.
Another thing related to the different engines is understanding the box model of development and how CSS is treated differently with it in each browser (and the different versions of the browsers). If you need to be extremely worried about pixel perfect matching between the browsers, you're going to have tons of fun.
Related to that, another thing is to look in CSS Reset Sheets. This gets the environment between the different browsers fairly similar. This makes development easier, but still not foolproof from messing up layout.
Usually you won't get any problems with ASP.net and cross-browser compatibility issues if you just use the standard normal server controls ASP.net gives you. When the problems start is (as CD said) when you're doing something more "advanced" like Ajax calls using the ASP.net Ajax Control toolkit or jQuery or whatever and you still have the requirement to be backwards compatible till IE6 (which causes most of the problems!).
What I experienced, cross-browser issues arise when
you're using a lot of client-side code like JavaScript (Ajax calls etc...). In such cases it is worth to look for high-level libraries like jQuery for doing most of the things.
you're dealing with CSS stylesheets for doing your page design and layout, which you should do with CSS and not inline styles!! With CSS it's a matter of learning by doing. You'll get experiences on what will work fine on most browsers and what will probably give you problems.
Generally, just for ASP.net, it is extremely important to have the page/control/custom server controls lifecycle in mind. You should have a good idea about that, but there is plenty information around on the web. Most issues you'll experience with the ASP.net ViewState will be due to incorrect handling of the according control's lifecycle (i.e. attaching dynamic elements to early/late, reading the ViewState in the OnInit of your page and wondering why your values are empty etc...)
This really should be more a concern of HTML markup and CSS than ASP.NET specifically. That will help your search.
For me this has been an issue of learning the hard way, along with a lot of Google searches.
Quirksmode.org is a good reference as Agent_9191 suggested and there are other more specialized & detailed references scattered throughout the web.
However, if you try to read and understand all the incompatibilities between browsers it's easy to be overwhelmed. So often times I really need specific examples to learn from.
For that, I really like alistapart.com. There is a ton of good stuff on that site when it comes to creating layouts in a cross-browser compatible way.
For the ASP.NET specific side, the most important tip I can think of is to avoid the more complex ASP.NET controls as much as possible. The more markup the framework generates, the more stuff you will need to unwind. And honestly, one can do everything one would need to do in ASP.NET using repeaters and user controls at the end of the day. Which is what one had to do back in the 1.1 days to get anything resembling decent markup.
Now, if you can't avoid the more complex controls, I would also check out the Css Friendly Control Adapters. They can help slim down some of the other stuff.

Tips for developing an ASP.NET application that doesn't depend on JavaScript

Not sure if this belongs in community wiki...
Can somebody give some general guidelines on how to successfully build an ASP.NET site that isn't dependent on JavaScript? My understanding is that I should build a functional site initially without JavaScript, and use it to enhance the user experience. That is easier said than done... how can I make sure my site works without JavaScript short of disabling JavaScript and trying it? Or is this something that comes with experience?
Try ASP.NET MVC! sure most of the examples use JavaScript for the AJAX functionality, but it's easy to build a fully functioning site that doesn't use JavaScript.
Since ASP.NET MVC doesn't use server controls with all their embedded JavaScript, it's a great way to build a site with very minimal and lightweight HTML, while still writting your data access and business logic in C#, VB.NET, or any other .NET language.
I've built working ASP.Net sites with little or no JavaScript, so it's definitely possible (just a royal pain.) The trick, and this sounds silly, is to use as few <ASP:> type tags as possible. Those all spawn various levels of JavaScript. Regular old-school HTML elements work just fine with no scripting.
So, on the extreme end, you write, say, your form using all plain-vanilla HTML elements, and then you have that form submit point at another page that accepts the form submit and hands it off to your server-side scripting.
To put it another way, pretend that all you get with ASP.NET is a snazzy server-side programming language and you're writing HTML in 1998.
Now, having done this, I can tell you that what this ends up as is a classic ASP webpage with cleaner programming syntax. ;) Most of the features that make ASP.NET "better" than classic ASP hang on JavaScript, so writing a JavaScript-free ASP.NET system is an exercise in shooting oneself in the foot repeatedly.
However, the one thing you should absolutely do is make sure the first page or two do work without JavaScript. Unlike 10 years ago you can safely assume that any browser hitting your page has JavaScript, and unlike about 8 years ago, your visitors probably don't have JavaScript turned off for speed reasons, but they very well might have something like the NoScript plugin for Firefox dialed all the way to 11. So, your first couple of pages need to work well enough to a) tell the new visitor that they need JavaScript, and b) still look and work good enough to make it look like adding your site to the white list is worth it. (In my experience, most people get the first one done, but in such as way as to totally drop the ball on the second. To put it another way - if your super fancy web 2.0 mega site starts looking like craigslist if noScript is fired up, I'm probably not going to bother letting you run scripts on my machine.)
If you want to use many of the ASP.NET controls (i.e. the DataGridView), ASP.NET pages are generated with lots of JavaScript in order to handle the events on the controls (i.e. selecting a row in the DataGridView). I think you're going to lose so much of ASP.NET that trying to have ASP.NET work without JavaScript enabled is impractical.
Disabling Javascript is the best way to test how a web site performs with out it. Good news, IE8's developer tools provide a quick and easy way to do just that. Now, having said that, often times the only thing that you can do is put up a message with a noscript tag to the effect that your site requires javascript for best function.
Many ASP.NET functionalities & controls won't work when JavaScript has been disabled. Think of LinkButton's onclick event which contains a call to a JavaScript function.
LinkButton is just an example. But there are many other things too.
If your concern is with JavaScript being disabled in user's browser then you can check for that and handle your site accordingly.
If you do decide to build the site without JavaScript then you will end up building a somewhat static web site. If your need is just to build a static website then you can go on with this approach.
Write everything with basic html forms and css, and then you will know that it works without javascript.
Once you are happy with it, then look at unobtrusive javascript, so you can modify the way the application works when javascript is enabled.
Last time I looked at some stats about this around 1% disable JavaScript, so why spend hours and hours on this when what you should do is show a message telling the user that your site requires javascript.
Use your time to be productive instead of trying to write around perceived limitations.

Do I have to use JavaScript?

When does it become unavoidable and when would you want to choose JavaScript over server side when you have a choice?
When you need to change something on your page without reloading it.
Designer perspective:
When you want to give more interactivity to your web page
When you want to load stuff without reloading (i.e.: ajax for example)
When you shouldn't use:
When You don't want to spend 1000 hours in pointless tries to disable the back arrow of your browser :)
Google maps would not have been possible without JavaScript. At least not in the form we know (and love) it today. So, depending on your ambition (and requirements) clearly: sometimes JavaScript is unavoidable, even though there exist technologies that take another approach that might have worked equally well (Java Applets, RIA technologies, etc).
If I had the choice I would probably chose JavaScript over a server-side implementation for a large number of applications, but then again, it is not a black or white picture. The server will remain important for web applications for a very long time to come.
Yes, you do. Now take out your textbook and turn to Chapter One. ;)
Honestly, though, to answer your question, I don't think it's ever "unavoidable," no; you can always code for the absence of JavaScript. (Indeed, usability best practices dictate you at least try to "gracefully degrade" the user experience for browsers that don't support it, or for users who choose not to.) In the beginning, of course, there was no JavaScript -- but there was still the Web. It just, well, kinda sucked.
There's no simple answer, but if you absolutely must have one, the most straight-ahead one I can think of is to use JavaScript to improve the user experience. Secondarily, use it to shift the workload from your server toward the browser (Hello, Ajax!) -- validation, state, etc. Those are two big reasons, broadly stated, IMO.
At a stretch, you could do everything via server-side programming. Some things will be painfully slow and difficult to pull off right, but it is possible. If you want to see something clever done with nothing more than CSS, try out the search feature on lxr.mozilla.org with scripting disabled.
Practically though, the best places to use javascript are where it'd otherwise disrupt the flow of what the user's doing - the AJAXy things on here are all pretty good examples, as is the realtime preview (everyone should have one of these!)
If it provides significant benefit, then it's completely fine to use it. But please, don't make it required unless the server-only equivalent is needlessly complicated.
I never want to choose JavaScript, but it becomes unavoidable when clients want a decent web app. JavaScript has the unique feature of low latency feedback in a browser - server side code doesn't.
Also, there are a (rather limited) number of times when it's actually easier to bust out some JQuery for formatting rather than dealing with ASP.NET's event model to manipulate client elements. But, I'd say those are relatively few.
If you are looking for a responsive UI and want to avoid JavaScript, consider some of the RIA technologies such as Flex, Silverlight or JavaFX. I've been developing with Flex since v1.5 and find it very capable and productive. Silverlight is getting significantly better with each release, too.
GWT is a nice system that compiles java code into javascript which becomes kind of like a "Machine language" for the browser--you never have to consider it.
I believe most google apps are written using GWT. It's pretty slick.
All your source code is pretty much straight Java using a library somewhat like Swing.
JavaScript is not a necessity but, coupled with the DOM API, it provides a very useful medium for gradually improving the user experience of your site. Obviously the extent to which this is true is dependent on how well you execute these enhancements, don't just use JavaScript for the sake of it; it's a design decision, and should not be taken lightly.
Sharing the load between client and server.
Try to keep it natural. Use it to enhance little things, do not built your whole application on JS.
A good way to measure the breadth of your skills is when "Do I have to use ..." starts disappearing from your conversation. Hopefully you get to the point where a language is just a language, and you develop a feel for what the right tool is for the job, and can use it as comfortably as any other language.
If it's any consolation, there's increasing evidence that there's enough conventional wisdom and available toolsets that developers are increasingly preferring javascript. I personally like it for its conciseness and easy exensibility - once you get to know it.
You don't have to.
But if you want to provide UI extras like autocomplete, drag and drop, richer form entry fields, etc.…, Javascript is your only answer.
Of course you can abstract that Javascript generation out to the server side but you'd still be tussling with Javascript, albeit via programmatic code generation.
When you create a Rich Internet Application which gets loaded into a browser and which communicate to a Web Server with an Open API (like SOAP, JSON etc)
"Javascript over server side " JavaScript is client side, not server side.
You would still need to run server side stuff to get the data from the server. Javascript just gives you more control on how the client receives the data from the server.
JavaScript is unavoidable when you want a certain dynamic feature on your website which is not supported by default.
Dynamic feature
- without JavaScript: you can use CSS to change background of an element when the mouse is over the element. You can do the same thing with using JavaScript.
- Only in JavaScript: When you click the element with your mouse, the element disappears. Don't think it is possible in CSS(maybe you be able to use :active in CSS on some elements. Never tested it myself).

Is elegant, semantic CSS with ASP.Net still a pipe dream?

I know Microsoft has made efforts in the direction of semantic and cross-browser compliant XHTML and CSS, but it still seems like a PitA to pull off elegant markup. I've downloaded and tweaked the CSS Friendly Adapters and all that. But I still find myself frustrated with bloated and unattractive code.
Is elegant, semantic CSS with ASP.Net still a pipe dream? Or is it finally possible, I just need more practice?
The easiest way to generate elegant HTML and CSS is to use MVC framework, where you have much more control over HTML generation than with Web Forms.
See this question for more discussion, including use of MVC. This site uses ASP.NET and the markup is pretty clean. Check out the HTML/CSS on MicrosoftPDC.com (a site I'm working on) - it uses ASP.NET webforms, but we're designing with clean markup as a priority.
As long as you use the Visual Studio designer, it's probably a pipe dream. I write all of my ASP.NET code (all markup, and CSS) by hand, simply to avoid the designer. Later versions of Visual Studio have gotten much better at not mangling your .aspx/.ascx files, but they're still far from perfect.
A better question is: is it really worth it? I write web applications and rarely does the elegance of the resulting HTML/CSS/JavaScript add anything to the end goal. If your end goal is to have people do a "view source" on your stuff and admire it, then maybe this is important and worth all of the effort, but I doubt it.
If you need the semantics, use XML for your data. I do believe in the idea of the semantic web, but my applications don't need to have anything to do with it.
As DannySmurf said, hand building is the way to go.
That said, you might look at Expression Web. At least it is pretty accurate in how it renders the pages.
#JasonBunting - Yes, it's absolutely worth it. Semantic and cross-browser markup means that search engines have an easier (and thus higher rankings) time with your content, that browsers have an easier (and thus less error-prone) time parsing your content for display, and that future developers have an easier time maintaining your code.
Yes - it's a pipe dream. Since working with a professional web designer on a joint project who HATED the output of ASP.net server side controls I stopped using them. I essentially had to write ASP.net apps like you would write a modern PHP app. If you have a heavy business layer then your page or UI code can be minimal.
I've never looked back since. The extra time spent writing everything custom has saved me a great deal of time trying to make Visual Studio / ASP.net play nice with CSS/XHTML.
i can't believe nobody has mentioned css adapters. many of the common controls used in asp.net (gridview and treeview for example) can be processed through an adapter to change the resulting html that is outputted to the browser.
if going the mvc route isn't a viable option, it is possible to write your own adapters for any of the built in asp.net controls.
http://www.asp.net/CssAdapters/

Resources