3

I am working in asp.net application, adding functionalities like form elements, validation and populating data from DB.

  1. I can use ASP: controls but I am wondering is it possible to use HTML.TextBox or <input type="text">

  2. If I can use <input type="text" or Html.TextBox what are the pros and cons of using them versus using

tereško
  • 58,060
  • 25
  • 98
  • 150
Ajax3.14
  • 1,647
  • 5
  • 24
  • 42

2 Answers2

4

Forget about server side controls in ASP.NET MVC. Everything containing runat="server" is a big NO in ASP.NET MVC. Won't work in Razor anyways. There are no pros and cons. Server side controls should never be used so there's nothing to compare. Simply use HTML helpers such as Html.EditorFor and Html.TextBoxFor.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 2
    my application is asp.net and guess it not MVC... So Razor is not recognised right.. moreover can you please elaborate the strong statement you made "server side controls should not be used" – Ajax3.14 May 01 '12 at 17:57
  • 2
    @Ajax3.14, server side controls rely on events, postbacks and view state. Those are notions that no longer exist in ASP.NET MVC. They have been replaced by html helpers. So if you are developing an ASP.NET MVC application you should use HTML helpers. – Darin Dimitrov May 01 '12 at 17:59
3

If you're using ASP.NET MVC, then either the manual typing (<input type="text" />) or the helper extension (Html.TextBoxFor(x => x.SomeProperty)) are going to be your best bet, and it really depends on what you are planning on doing. If the control you are making has no property on your element, it can be a lot easier to simply hand code the input tag.

Never use <asp:Checkbox ID="blah" runat="server" /> in an MVC application.

Tejs
  • 40,736
  • 10
  • 68
  • 86
  • my application is just asp.net so you think your answer is still applicable in asp.net..can i use (Html.TextBoxFor(x => x.SomeProperty)) – Ajax3.14 May 01 '12 at 18:00
  • If it's traditional WebForms, then do completely the reverse. – Tejs May 01 '12 at 18:16