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

后端 未结 3 1324
刺人心
刺人心 2021-02-19 01:59

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 over usi

相关标签:
3条回答
  • 2021-02-19 02:35

    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.

    0 讨论(0)
  • 2021-02-19 02:42

    You can add a runat="server" attribute to any regular HTML tag in ASP.NET WebForms and it will be available to you in code behind as an HtmlGenericControl. You can set the text via HtmlGenericControl.InnerText and the HTML via HtmlGenericControl.InnerHTML.

    An advantage of using an ASP.NET TextBox is you can have it render as an <input type="text" /> or as a <textarea /> (TextBox.TextMode="multiline")

    Please see msdn.microsoft.com/en-us/library/7512d0d0.aspx and msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx

    0 讨论(0)
  • 2021-02-19 03:00

    <asp:TextBox> is a serveriside control wihich eventually gets converted to <input as page gets rendered to html.Similar to <asp:TextBox> you will see that there are other controls which will get converted to standard HTML elements.

    <asp:TextBox>
    

    Is a serverside control so that you can access it in codebehind using its ID hence you can even perform .visible = true or false actions in code behind .

    These might help

    ASP.NET Server Controls
    Advantages:

    1. ASP .NET Server Controls can however detect the target browser's capabilities and render themselves accordingly. No issues for compatibility issues of Browsers i.e page that might be used by both HTML 3.2 and HTML 4.0 browsers code to be written by you.
    2. Newer set of controls that can be used in the same manner as any HTMl control like Calender controls. (No need of Activex Control for doing this which would then bring up issues of Browser compatibility).
    3. Processing would be done at the server side. In built functionality to check for few values(with Validation controls) so no need to choose between scripting language which would be incompatible with few browsers.
    4. ASP .NET Server Controls have an object model different from the traditional HTML and even provide a set of properties and methods that can change the outlook and behavior of the controls.
    5. ASP .NET Server Controls have higher level of abstraction. An output of an ASP .NET server control can be the result of many HTML tags that combine together to produce that control and its events.

    Disadvantages:

    1. The control of the code is inbuilt with the web server controls so you have no much of direct control on these controls
    2. Migration of ASP to any ASP.NET application is difficult. Its equivalent to rewriting your new application
    0 讨论(0)
提交回复
热议问题