serverside controls vs html controls from AJAX point of view - asp.net

i know this question have been mentioned alot here but mine is a little more updated,
now with ASP.net 4 and new Ajax client templating plus JASON services.
so if i got all these new capabilities will i really need server side controls as long as i can bind on client side, create data-views on client side heck i can even use data-context and apply CRUD operations on clients side.
so i actually i wont need button_click server side event or what so ever...
i am asking this because i own some commercial Controls like Telerik and Component art and they both offer client side operations ow but still i am confused as to my knowledge creating these controls will still have to go through Page Life cycle
please advise me.

The last Webforms app I created I had very few server controls on the page. Any save or update action I used plain HTML controls and jQuery for AJAX. I don't use any third-party control packs, but I know if you use jQuery you can find a jQuery plugin that will do what you need. There are hundreds of them out there and they're free.
If you are thinking about avoiding the page life cycle then I strongly suggest looking at the asp.net mvc framework. It allows for a lot more freedom and control over the HTML you produce. This makes it much easier to do AJAX and jQuery.

Related

Conversion from Coldfusion to Asp.net (Drag and Drop Functionality)

I have Coldfusion web application that has a CF query from a database table. This data is displayed in an HTML table with a checkbox beside each data item and an associated picture. There is Jquery functionality on the page so that the items can be re-arranged in the table based on the users preference. After the user finishes with their re-arrangement, it is re-displayed without the checkboxes for sending as an email. Note I did not write this application myself but inherited it...
I need to transfer this functionality to a asp.net C# web application but i am at a crossroads on how to proceed. I've looked at telerik controls and others but none appear to fit the functionality i need. Any solid suggestions?
I'd suggest to handle rendering of the table yourself. If you're using asp.net webforms, this can be done with a custom server control. If you're using asp.net mvc (which I suggest as MVC matches the coldfusion development model a bit closer than webforms), then it's much simpler and you can just do so in the view.
Once you are rendering the grid yourself, then it's simple to apply the jquery functionality on the client-side.
Without more info about what you can or can't do, it's a bit difficult to offer any more guidance. But you did only ask for suggestions :-)
Asp.net doesn't mean you need to use a library control built for .net. jQuery is powerful enough today, and it's not tied to any back end technology.
So, that being said, I would still go with jQuery and back it up with RESTful request using webservices with WebForms or controllers with MVC.
Have a look at this: JQuery Drag and Drop features with ASP.NET

Using jQuery-AJAX to page ASP.NET datagrid

Does anyone have, or could point me to, an example of using jQuery to page through an ASP.NET datagrid control?
I would like to page through a large set of data displayed by an ASP.NET DataGrid control however I would like to avoid a page refresh and hence want to use AJAX to get the new sets of data. I would also like to avoid the ASP.NET AJAX toolkit and would like to do it all using jQuery-AJAX. Thank you.
The DataGrid is a server side control that relies on postbacks. jQuery and AJAX are client side technologies. Write a AMSX or WCF service to serve up your data and consume it with jQuery. You can use jQuery templates to make things easier. Or wrap the DataGrid in an UpdatePanel and you will have the poor man's AJAX(sometimes called AJAH).
There may be a jQuery plugin to help with this.
Here's a nice article to get you started:
Easily build powerful client-side AJAX paging, using jQuery
Try using jGrid, it´s free, but there are commercial dotnet implementations available.
It´s quite powerfull,you can do almost everything with it. And loading your data is easy to. But, you have to forget the Idea of aspnet datagrid, unless you will use updatepanel(which is very stable and usefull and has nothing to do wiht asp net ajax toolkit)

ASP.NET (webforms): Using with MINIMAL server controls and substituting with JQUERY?

I am currently working with ASP.NET and the person who designed the form has used all Server Controls for things like TextBoxes and Dropdowns etc when really they are not providing postbacks.. Some of the dropdowns and textboxes are values that I need only in jQuery so as far as I can see there are no drawbacks to coverting these controls to standard html controls rather than ASP.NET server controls?
I suppose I will need to continue to have my GetDataGrid button as a server control because I will need it to postback (and receive PageLoad events etc - all asp.net events) to update the GridView? Or would it be possible to use the GridView (ASP.NET server control) from a Webmethod and call it via Jquery?
Of course in my webmethod I would need to the instance of the gridview to add the datasource - but I don't see how this would be possible without being in the ASP.NET events - or maybe I wrong?
The other thing I thought of was changing the GetGridView button to a standard HTML and calling the javascript postback from the client click event?? This way it would do a real postback and I would end up in Page_load.
Taking everything into effect i don't want to the change the GridView asp.net control as it funcions well as an asp.net server control but i am unsure how i would do this.
I remember a document being available that said "how to use asp.net webforms without server controls" but i can't seem to find it. I suppose using webforms like asp.net MVC - but i can't change the project to MVC - its out of my control.
I would love to hear some feedback with regards to how to do this or comments etc.
I find ASP.NET webforms to inject a lot of code smell into pages - I am using .NET 3.5 so a lot of the output is with tables etc...
If you use Request.Form["..."] then you can get the information which was filled in in standard html input fields.
Instead of keep on using the GridView control I suggest you take a look at either jqGrid or the new templating system that Microsoft put into place for jQuery (currently a plugin but expected to be part of core jQuery from version 1.5 on). These can bound to json which can be retrieved from a webmethod or pagemethod call to fill up the template with data.
Also i don't think its possible from asp.net (code behind) to receive values of an html >control without it having runat=server.
Use webmethods.
Set a client event (like 'onchange') on the html control and then in javascript function called when the event is fired you can use PageMethods to send your data to the code behind.
Some thoughts...
The GridView can't be created in a WebMethod and even if there was a way to get that to work, you'd be better off going with a genuine client side grid. As that's not an option, I don't think there is too much point in trying to make any major changes to your existing pages.
ViewState
Changing the textboxes, buttons etc to HTML versions, would gain you a little bit in reduced Viewstate size but add a bit of complexity in how you handle interactions with the page. You can add runat="server" to HTML controls which will give you control over what is rendered and still have access to the control on the server side.
.Net 4 gives you far more control over viewstate but unfortunately in 3.5 its not as easy.
The GridViews
You could wrap the GridViews in UpdatePanels. That's a 'cheap' way to add some interactivity to your pages although you won't be gaining anything in terms of performance.
It's also still possible to manipulate the Gridview using jQuery on the client-side. There a lots of tutorials, blog posts etc explaining how to do this on the Internet.
MVC with Webforms
Its also possible to mix ASP.Net MVC with Webforms in the same website. As it sounds like you are familiar weith MVC, you might want to consider this approach for any new pages. Here's a blog post explaining how to do this.
Update:
Here's a more recent article by Scott Hanselman on how to use MVC with an existing Webforms application.

Is it Asp.Net or Ajax or can both technologies be used together when developing web sites?

1) A while ago I’ve started learning Asp.Net, but then I’ve heard that Ajax is “the new thing”. Since I don’t want to throw away the time I’ve invested into Asp.Net, I’d like to know if it is a common/recommended practice to use both technologies ( Asp.Net and Ajax) when creating websites and web apps in general?
2) If it indeed is a common practice to use the two technologies together, is that only true for server-side Ajax and Asp.Net or can client-side Ajax also be used in conjunction with Asp.Net?
thanx
EDIT:
A)
The only problem is that it can be a
bit trickery to do ajax request using
jquery when using asp.net
webforms(asp.net mvc was designed with
frameworks like jquery in mind so it
is easier to do).
Are you implying that perhaps jquery could be too much of a hassle when used together with webforms and thus I should think of using Asp.Net Ajax instead?
B) Little I read on ajax is that it also needs to call web services or some other technology that provides similar functionality to web services. If true, which technology do you use ( WCF or Asp.Net web services or … )?
C) Is Ajax a subsection of jquery? Thus, to understand Ajax, will I need to purchase only a book on jquery or will I also need to read a book with Ajax in its title?
You can use both, and it is common to use both. MS has a toolkit around using AJAX on asp.net sites:
http://www.asp.net/ajax/
1) Yes it is common to use Ajax and Asp.net on the same website. I do it all the time(in fact if you turn off javascript on my sites they won't work too well as so much is AJAX). AJAX allows for requests to the server to be made without refreshing the page you still need a serverside language to do stuff with that request. You also need the load the page for the first time so asp.net controls still are needed and in fact if your using asp.net ajax then you can use update panels where you put controls into that automatically become ajax enabled.
2) I am not sure what you mean but Ajax is mostly javascript so it lives on the client side and sends requests to the server side.
Edit
Ok I skimmed most of the stuff in those chapters. AJAX server side is where most of the rendering is done on the server side. So the update panel is an ajax server side control. You drag it on to your webform throw some other server side controls into it and a button. If a user then clicks on that button in the update panel an ajax request is made to the server and you can grab all the stuff you need and use C# to change it. You never have to write one line of javascript code to make that happen.
Of course that has a price though for instance an update panel does not do a true ajax request because of the page life cycle. If you actually watch the code through the debugger you will notice it will go through the page life cycle but in the end will just rerender that update panel so there is a bit more over head then if you did it yourself.
Client side Ajax is basically Microsoft trying to make it easier for you to do javascript by trying to make it more like C# syntax and giving you built in methods. A problem is that alot of people throw the buzz word Ajax too often around and call stuff that should not be called Ajax when it should be just called javascript.
This seems to be the case with this client side ajax as most of what I seen in the client side ajax chapter is almost all javascript. Like in "Figure 33.8. Selecting a menu item." all it seems to be is your click on a choose then it displays the name of that button that is not really Ajax.
Ajax to me is when you actually make a server request to post or get some information with out the page refreshing(ie full post back). For example if you got a form of data that you want to send to the server to be saved in a database. If you would hit the save button and that form data would be sent to the server without the page refreshing then that would be an Ajax request.
Most of the stuff in the ajax tool kit is more javascript
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Calendar/Calendar.aspx
For instance the calendar control to make it select different dates it is not doing any sort of request to the server since it is all javascript so why would it be ajax if it never posts to the server?
If you would take the value in the textbox that the calendar control puts the date in and post it to the server without refreshing the page that would be an Ajax request.
Finally I would not be too worried about asp.net webforms going anywhere anytime soon. I believe the guy who wrote that article about asp.net going to dye is the guy who made Ajax or was involved some how with the development of Ajax so he is probably biased.
Besides look its been 5 years now since he posted that and asp.net is stronger then ever. Ajax still needs a server to connect to, you still need to render the initial page load with either straight html or asp.net server controls.
Edit 2
1) Yes I think jquery is better the MS ajax for a couple reasons:
It uses less resources then drag and
drop controls
It simplifies javascript alot as it
makes it easier to use(such as
selecting html controls,etc). So if
I was using MS ajax I probably still
be using jquery for the selectors it
has so it is kinda redundant to use
both unless you have a good reason
too.
The only problem is that it can be a bit trickery to do ajax request using jquery when using asp.net webforms(asp.net mvc was designed with frameworks like jquery in mind so it is easier to do).
2) You really only need to learn jquery and not even javascript. I read a javascript book in like a day then jumped into jquery without even doing on exercise in the book and never did javascript before and I had no problem doing jquery. Of course if you got javascript experience it is a plus since sometimes you will be trying to find a jquery solution when javascript already has a method for what you want to do.
Edit 3
A)
The only problem is that it can be a
bit trickery to do ajax request using
jquery when using asp.net
webforms(asp.net mvc was designed with
frameworks like jquery in mind so it
is easier to do).
Are you implying that perhaps jquery
could be too much of a hassle when
used together with webforms and thus I
should think of using Asp.Net Ajax
instead?
No I am not implying that it is too much hassle for webforms was just stating the fact that it will be a bit more tricky in certain situations then ms ajax and jquery with say asp.net mvc.
asp.net webforms was not really made for a framework like jquery and has trouble dealing with it because of it's page life cycle gets in the way. MS ajax might have it's own set of challenges though too(like everything usually does). Jquery was made in mind of to try and work across all browsers since in javascript many times you would write something that worked in IE but did not work in any other browser and I am not sure if MS ajax client side version thought about this.
B) Little I read on ajax is that it
also needs to call web services or
some other technology that provides
similar functionality to web services.
If true, which technology do you use (
WCF or Asp.Net web services or … )?
Yes this is true. This was the whole point many people including me where trying to make to prove that guy was wrong that asp.net was dying because of ajax, since you need something in the back end to make a call too.
However you can choose whatever you want. You can make a separate web service( can be a asp.net web service), you can have like static web service methods in your page load ( I never done this way) and the way I use to do it is by making a generic ajax handler.
You can't however just make a regular method in your page_load and try to call it as it has to go through the entire page life cycle.
http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
http://weblogs.asp.net/craigshoemaker/archive/2008/11/07/using-jquery-to-call-asp-net-ajax-page-methods-by-example.aspx
http://dotnetslackers.com/articles/ajax/using-jquery-with-asp-net.aspx
http://sites.google.com/site/spyderhoodcommunity/tech-stuff/usingjqueryinaspnetappswithhttphandlersashx
I have not read these tutorials but these tutorials should show you the 3 different ways you can do an ajax request to an asp.net webservice, asp.net code behind page and asp.net generic handler.
Choose what ever one you think is best. I don't know if one way is better then another and there probably are more ways to do it.
C) Is Ajax a subsection of jquery?
Thus, to understand Ajax, will I need
to purchase only a book on jquery or
will I also need to read a book with
Ajax in its title
Ajax is just part of jquery and probably won't take you long to learn. If you buy a book about jquery there will probably be like 1 chapter on it. The only down side is all the jquery books I know of are all in php.
So if your just buying it to learn the ajax part probably not worth it since they will show an entire example of how to do it with php that might be slightly different then if you did it with asp.net( mostly just setting up the server side to accept the jquery calls- see the links that I posted above).
If you want to learn jquery selectors and stuff then it does matter if the one chapter is in php since it's all client side stuff expect for the ajax part( what is client side and server side).
It's not hard to really do the ajax stuff it just knowing what path you need to choose and more how to accept stuff on the server side and return stuff from the server side.
$.post("test.php", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
The above is basically all you need to do on jquery side to send some ajax stuff. The first parameter is the path where this request should go. In this case its some php file called test. The next parameter is the the actual data sent as a json result and finally the last line is the function call back line. When the ajax post request is done that line gets called and does the actions. Data is the returned stuff you sent back from the server.
http://api.jquery.com/jQuery.post/
So I would just go through the tutorials I posted and play around with the jquery selectors. Once you done that you can decide if you want to go with jquery or not. The last thing I wanted to point out about why I like jquery is the fact that if you learn the MS ajax stuff your basically stuck with asp.net( what I have no problem with since I love .Net) but with jquery you can easily take your code or those skills of jquery and use it with php, ruby or whatever else and all the client side jquery selectors won't change by switching a different language. The only thing that will be different is the ajax stuff and even that won't be 100% different as the jquery ajax client side could will be the same.
Ajax is a methodology which can be used in conjunction with with other frameworks, such as asp.net. Asp.net will allow you to integrate javascript to implement ajax solutions.
A common implementation is to use javascript to call an asp.net webservice to perform ajax operations.
Ajax is the new "old thing" - ASP.NET MVC is the new "new thing" :-)
But seriously, you can mix all of these technologies in one web application if you want:
"classic" ASP.NET (WebForms)
Ajax (using ASP.NET Ajax controls other approaches such as jQuery)
ASP.NET MVC.
AJAX is a technique essentially added on top of an existing website to allow things to be done on that page without refreshing the entire page. Here on StackOverflow, for example, you can vote by clicking the up/down arrows via AJAX, without the page refresh you'd have seen without AJAX.
It doesn't replace ASP.NET (or any other language).
AJAX does not replace ASP.NET. They can be used together or independently. ASP.NET is more of a framework, where AJAX is a set of techniques built on top of JavaScript and HTML.
There is a framework that Microsoft has called ASP.NET AJAX. There are controls that will output JavaScript so that if you wish, you can have AJAX functionality without having to get too far into JavaScript.
However, you could also write the JavaScript by hand and use XMLHttpRequests to send requests to ASP.NET URLs and get data back.
ASP.Net is primarily a server-side technology stack which dynamically generates most of the client-side code. The out-of-the-box ASP.Net 2.0 page model is a fairly painful way to implement AJAX-enhanced user interaction (though there are techniques, such as custom handlers, that make it pretty tractable). Both the ASP.Net MVC and ASP.Net AJAX frameworks provide helpful tools for making it lest troublesome.
AJAX is commonly used to describe any asynchronous, partial-page-interaction technique to build the user interface of your application.
The server-side technology and the client side technology choices are fairly independent, though different techniques for how to work with a client side technology become attractive with different frameworks on the server.

Confused with asp.net controls and html controls

We are plannning to use Ajax in our ASP.net project. However, we still want the member panel of our web site to work in all browsers. We have decided not to use Ajax in some forms where browser independence is must.
I am now confused with whether we should use ASP.NET controls or HTML controls or both?
I have two questions:
Are there any problems that I might face using either of approach?
Also which one is better considering efficiency and performance?
The Asp.Net Controls including the ajax controls are independent of browsers, asp.net will detect your browser and try to render the best html/javascript for that browser. So you are good with server controls.
If you are going to implement the project in asp.net then for all the controls that need to be accessed via code at server side needs to be asp.net controls. Those controls that are static and only displaying some value can be html controls.
The main point is that the asp.net controls are rendered to html controls... so the client who views the web-page actually gets the html controls.
For AJAX refer this
ASP controls and HTML controls as complementary.
ASP controls bring facilities for programming like the viewstate (the control keeps its content after a post back), the binding with datatable, and a lot of presentation properties. It is really an advantage in terms of time and maintainability to use these controls. They also manage some security feature like html code injection. ASP controls could be controled and managed from the code behind page.
HTML controls are out of the native ASP.NET page process. It is sometime a good thing to have particular control that you don't want ASP.NET take in charge and modify, but it is not the core of an ASP.NET web application.
If you can use HTML - it is always better - as it is much faster.
The use of ASP controls should work on all browsers as far as I know, but it less efficient.
Better create a small example and test it on some browsers before you decide.
(I've used ajax on both explorer and Firefox and it works)

Resources