asp.net controls: what's the point of them?

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
I'm fairly new to ASP.net programming, and I'm puzzled as to why ASP.net has all these controls like <asp:RadioButton> that replaces <input type="radiobutton">. All these controls do is generate html and javascript, so why not just write html and javascript?
 

Bulldog13

Golden Member
Jul 18, 2002
1,655
1
81
ASP.net controls allow server side processing. It makes programming for the web more similar to programming for a FAT application. They expose events such as Click(), IndexChanged(), so you can very straight forwardly process those events and input.

They generate the html and javascript for you, so you don't have to worry about it. Makes for rapid application development.

That being said, most of the MS web developers I know quickly outgrow them because you eventually face limitations in programming with them, since you lack control of the "bare-metal" JS and html that is there and heavy customization of them becomes tricky.

But. I do <3 the gridview. Before I started developing in MVC I learned to make that thing do all types of tricks.
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
Actually OP, the trend is coming back around to client side processing. For a time, ASP controls offered quick and powerful programming utility to allow server side processing for any rich web application.

For the past couple years, the trend is to minimize postback related phenomena and make web applications look and behave more like a thick client. In that sense, there is not much need (or desire) to use built-in ASP controls for server side processing, rather use ajaxian process and more client side scripting communicating via service or remote method to process server side needs.

If you asked this 10 years ago, you would have gotten a much difference response, I'd gather.

@Bulldog: Have you taken a look at ajax gridviews? Oh my god those are beautiful.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Actually ASP.Net controls do much more than just output html. The best example is, say you have a user who submits a form, but fails to include some required field. In traditional ASP the programmer would need to check the required fields, write an error mesage about the missing required field and then fetch and put the entered values back into their respective fields. You can't have the user have to re-enter all of the data again or they will give up and leave your site.

ASP.Net controls handle this all for you. They fetch the value from the Form array and put it back into the field. They store into ViewState their properties like background color and font size so these properties stay consistent when the form is submitted and then is sent back to the user. They really are quite useful and helpful.

As mentioned above they have fallen out of favor because they use a base64 string in the html to encode a "ViewState" to record all of these control properties. The view state can get very large very fast which greatly reduces performance for the webserver.
Much more work is done on the client now with javascript, instead of posting back to the server.
 

Bulldog13

Golden Member
Jul 18, 2002
1,655
1
81
Actually OP, the trend is coming back around to client side processing. For a time, ASP controls offered quick and powerful programming utility to allow server side processing for any rich web application.

For the past couple years, the trend is to minimize postback related phenomena and make web applications look and behave more like a thick client. In that sense, there is not much need (or desire) to use built-in ASP controls for server side processing, rather use ajaxian process and more client side scripting communicating via service or remote method to process server side needs.

If you asked this 10 years ago, you would have gotten a much difference response, I'd gather.

@Bulldog: Have you taken a look at ajax gridviews? Oh my god those are beautiful.

@KIAMAN - Do you have one you can recommend I look at ?
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
@KIAMAN - Do you have one you can recommend I look at ?

http://samples.gaiaware.net/BasicControls/GridView/Overview/

That has a good example of an ajax gridview but has a few bugs. I've actually created several of my own ajax gridviews and gave them a huge list of features all without increasing load on the server.

I'm not sure how familiar you are with ajaxian in general, but there is a lot of cool things you can apply to a page to make it feel like a thick client without VMs.
 

BigDH01

Golden Member
Jul 8, 2005
1,631
88
91
I'm fairly new to ASP.net programming, and I'm puzzled as to why ASP.net has all these controls like <asp:RadioButton> that replaces <input type="radiobutton">. All these controls do is generate html and javascript, so why not just write html and javascript?

It's still pretty convenient to use ASP.NET controls for event handling and displaying of some types of information (like Gridviews for tables). And the AJAX control toolkit extends these controls with more client-side javascript which is extremely convenient. Updatepanels can still be convenient for updating large parts of the page, but you still have to deal with the viewstate and the html response, which can be rather slow.

I think like all devs, I find myself moving more and more to just writing the jQuery and jQuery UI myself and doing AJAX with pagemethods and JSON. .NET makes these things pretty easy, although it's not that difficult to do in PHP and other languages. For most things now, I'm basically using .NET to render the page the first time and using javascript beyond that. I'd prefer to move to PHP, but that's not my choice.

Also, for those looking to replicate a lot of the gridview's functionality but in javascript, take a look at DataTables, a plug-in for jQuery.

http://www.datatables.net/
 

PingSpike

Lifer
Feb 25, 2004
21,758
603
126
Do ASP.Net controls not allow server and client validation? My (sort of awful honestly) book suggested that they can do client-side, server-side or both to account for a client having javascript disabled. It didn't elaborate on this concept at all though, and it left a lot of my classmates wondering if it uses javascript on the server side or what? We never got an answer on that.
 

Hmongkeysauce

Senior member
Jun 8, 2005
360
0
76
Do ASP.Net controls not allow server and client validation? My (sort of awful honestly) book suggested that they can do client-side, server-side or both to account for a client having javascript disabled. It didn't elaborate on this concept at all though, and it left a lot of my classmates wondering if it uses javascript on the server side or what? We never got an answer on that.

I believe most ASP.NET controls (those that support postback) offer an OnClientClick event which you can use to fire any javascript functions/validations.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
ASP.Net server side validation will be done in a code-behind file, typically written in C# or VB.net. Javascript is only used client side.
 

PingSpike

Lifer
Feb 25, 2004
21,758
603
126
ASP.Net server side validation will be done in a code-behind file, typically written in C# or VB.net. Javascript is only used client side.

That makes sense, and was sort of what I suspected. It's a shame they couldn't have added that one sentence in the book. I didn't see why it would be running the javascript on the server side.
 

BigDH01

Golden Member
Jul 8, 2005
1,631
88
91
That makes sense, and was sort of what I suspected. It's a shame they couldn't have added that one sentence in the book. I didn't see why it would be running the javascript on the server side.

http://msdn.microsoft.com/en-us/library/aa479013.aspx

Double-Checking Client-Side Validation

One interesting point is that even though the form data is validated on the client (eliminating the need for additional requests to and responses from the server to validate the data), the data entered is re-verified on the server. After the data is checked on the client and found valid, it is rechecked on the server using the same validation rules. These are rules that you establish to ensure against some tricky programmer out there trying to bypass the validation process by posting the page to the server as if it passed validation.

These controls are double-checked on the server automatically, and confirmed with Page.IsValid. You can confirm this behavior by calling OnClientClick to an AJAX function which posts the form data via JSON to a webmethod. You'll find that the validation controls no longer work (on the client-side).

ASP.NET MVC uses jquery.validate which tosses attributes in the inputs themselves for client-side validation. They also do a lot of validation automation for you by allowing you to specify in your classes how information should be validated. So if I have a property in a class called Name, I can put [Required] above it and use @html.validatorfor(model => model.Name) and it will automatically do client and server-side validation for you. That's pretty nice, and should be coming to Web Forms soon as well.