Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp:Textbox vs input text (a PHP Developer learning ASP)

Tags:

php

asp.net

I’ve been a PHP developer for 10 years, trying to broaden my horizon I am doing a project in ASP.NET. What is the advantage to using an <asp:TextBox> over using a standard <input type=’text’>?

It seems advantageous to use a regular <input type=”text”> over <asp:TextBox>. First, when the page is rendered, the <asp:TextBox> becomes a standard <input type=text>. When I use a standard <input type=”text”> I can easily retrieve their value with in serverside code, via Request.Form["Name"]. Next when I dynamiclly add inputs (via javascript) I can’t use TextBox’s I need to use <inputs type=”text”>. Finally wouldn’t it be faster to render the normal input? If I code with <asp:TextBox>, that has to be rendered where if I use <input type=”text”> it simply needs to be displayed.

In otherwords why bother with all the asp controls when standard inputs work just as well and if not better…

like image 851
user889829 Avatar asked Aug 30 '11 18:08

user889829


People also ask

What is ASP TextBox?

ASP.NET Web Forms TextBox. This is an input control which is used to take user input. To create TextBox either we can write code or use the drag and drop facility of visual studio IDE. This is server side control, asp provides own tag to create it.

How do I style a TextBox in asp net?

The only way to ensure that would be to add a class or put it inside a span element. Show activity on this post. This will then apply the CSS class "textbox" to every textbox in your site, assuming you have corresponding CSS and theme references.

Which is the only input control in asp net?

ASP.NET supports only one input web control: the TextBox. The TextBox behaves like a single-line or multiline edit control, depending on the value of its TextMode property.


1 Answers

What is the advantage to using an over using a standard <input type=’text’>?

  • You can reference the textbox a little easier in the code-behind page
    • A note that you can acess any HTML element in the code-behind by using runat="server" inside the control
  • You have access to more properties on the textbox than the input html element
  • You can use textboxes with other ASP.NET controls like validators
  • You can perform data-binding easier with them than inputs
  • You can attach events with textboxes easier and almost effortlessly compared to using input and javascript

Comparative Summary

  • Faster/easier programming
  • Compatibility with other ASP.NET controls

Next when I dynamiclly add inputs (via javascript) I can’t use TextBox’s I need to use <inputs type=”text”>.

Whether your using ASP.NET or Javascript, dynamically added controls gets very messy. It's much easier to hide/show controls when needed (or use repeaters or datagrids).

Finally wouldn’t it be faster to render the normal input? If I code with , that has to be rendered where if I use it simply needs to be displayed.

I don't think it's fair to compare the speed of ASP.NET to HTML/Javascript applications. ASP.NET was meant to render ASP.NET controls, and using HTML controls inside an ASP.NET isn't going to have any noticeable performance gains.

ASP.NET vs HTML/Javascript

I feel like your question essentially amounts to "Why not use a brick on a nail, rather than a hammer?" ASP.NET is a framework, and was built with ASP.NET controls in mind. It's purpose is to allow things to be programmed faster, easier while abstracting away most things (usually trivial, repetitive ones) that would normally be done with Javascript.

like image 154
rlb.usa Avatar answered Nov 03 '22 09:11

rlb.usa