|
-
Jul 16th, 2004, 08:48 AM
#1
web forms html or server controls?
being new to ASP.NET, whats the deal with the runat server controls like the command button versus the HTML controls like the button and textbox, etc...
when should one be used versus the other?
-
Jul 16th, 2004, 09:41 AM
#2
Fanatic Member
.net controls can maintain state unlike their HTML equivalents so after you have filled in a .net textbox and submitted it to the server, when the control is rendered in your browser again the text box still has it's contents.
.net controls also have properties which can be altered in code like .text .enabled . visible e.t.c.
They can also fire off events like windows controls so selecting something from a listbox can fire off the index_changed event and so on.
I moved over to .net from asp and found it very wierd to begin with but it is so much better and faster.
-
Jul 16th, 2004, 09:42 AM
#3
so why would you ever want to use regular HTML controls if they have replaced most of them with ASP.NET controls?
-
Jul 16th, 2004, 09:52 AM
#4
Fanatic Member
.net controls are heavier so if you don't need any of the features of the .net controls then use HTML.
I never use HTML controls unless I need a textbox of File type.
-
Jul 16th, 2004, 10:10 AM
#5
Frenzied Member
Keep in mind, server processing is expensive. So if you don't need the functionality .net controls and code offer, then don't waste it. Because what your .net server has to do is render everything into HTML and send it to the client. When you view the source of a .aspx page while browsing, it looks totally different than your source because it's HTML.
Just a side note but you can do a lot of cool stuff with client-side Javascript (like alerts or popup windows) that you just can't do with server-side code. A good rule is anything you can do on the client, do it.
-
Jul 16th, 2004, 04:26 PM
#6
I wonder how many charact
Just a sample reason:
IF you have a window that pop's up, and you have a Close button on that window, you could make it either a .Net Button, or use a simple <input type=button tag.>
Having the close button as a .Net Button means the server goes through the trouble of instantiating a button class, assigning any non-default properties, and calling the class's render method when it comes time to render the page, saving the control's viewstate to the page's statebag. Additionally, on post back, the server must re-construct the button, assign any viewstate...etc...
With a simple <input type=button> tag, the server just writes the html out, no implicit processing....
So, for a Close button, you only need an input tag, assigning window.close to its onclick event. Since you won't change the text on the control, and won't change its functionality, dependant on some data or anything.
-
Jul 16th, 2004, 11:32 PM
#7
PowerPoster
Originally posted by wey97
... A good rule is anything you can do on the client, do it.
Be careful with that rule, JavaScript isn't always enabled on the client, so have backup plans.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|