1

In my asp.net web control form i am using two text box 1st is simple input html control and 2nd is asp.net input web control.

<form id="form1" runat="server">

        Email: <input type="text" id="txt_email" name="txt_email" value="" /><br />
        Email2: <asp:TextBox ID="txt_email2" runat="server"></asp:TextBox><br />       

        <asp:Button ID="btn_login" Name="btn_login" runat="server" Text="Button" 
            onclick="btn_login_Click" />

    </form>

I need to know what is the difference using simple control and asp.net input control both of them pass the value to code behind after the form submit. can any one help me on this?

3 Answers 3

1

As defined in your example input type="text" won't even be visible to code-behind because it is missing runat="server" attribute.

If you do add it - there're still differences. ASP.NET TextBox is more advanced and in par with the rest of ASP.NET model (e.g. it has property .Text vs. .Value of an HtmlInput control, it has events and other properties).

But if you simple need to pass text information back to the server, either of them will do the job.

Sign up to request clarification or add additional context in comments.

2 Comments

Yours is the most simplest & great explanation.So, is it like that all asp.net controls are actually rendered as HTML controls in the end to the browser, just that they have events and other properties that provides a great flexibility and control over normal HTML controls. So can we infer that HTML control events can also be used with these asp.net controls? like onchange event of dropdownlist ?
@FlopScientist Exactly. Every ASP.NET control is rendered as an HTML control in the browser (more complex ASP.NET control can render as multiple HTML controls - see GridView, Calendar, RadioButtonList etc.) But essntially yes, they render as HTML control that can use same client-side events as standard HTML controls. E.g. DropDownList renders as SELECT control in the browser which definetly can use onchange event.
0

The biggest differences are that

  1. the asp.net controls are rendered on the server, and thus they have more overhead on your server than using traditional controls - traditional controls (by default) are rendered once then basically reside on the client's browser, asp controls are persistent on the server side.
  2. the asp controls can be accessed and worked with directly in the code behind files.
  3. asp controls have some additional tags that can be used on their fields usually.
  4. as was pointed out by @Yuriy-Galanter, how the value is accessed is slightly different.

Comments

0

The asp:Textbox renders HTML to the client/browser when the page request is made. Picture the ASP.NET control, in this case an asp:TextBox as a server side bit of code that knows to render a <input type="text"> HTML element when the request for the aspx page is made to the server.

The ASP.NET compiler, when parsing your aspx page just spits out the <input type="text"> HTML element you have for Email: and for Email2: the ASP.NET compiler knows that is a server control because of the runat="server" tag. So the ASP.NET compiler, having a reference to the ASP.NET assemblies on the server, reads the code for the <asp:TextBox> and knows to ultimately respond to the page request with an <input type="text" id="txt_email2" />

The server side controls are accessible in your code behind page. So is accessible in the code behind but the <input> element is not. Good for you to consider in your research at this point, that if you add runat="server" to your element, it is accessible in your code behind.

1 Comment

You are saying that 1st control with type="text" will not be available on code behind, but i have tested this code as i have mention both of the controls pass the value to code behind. but the difference i have found is asp.net control keep the value after the post back and simple html control did't keep the value it just show empty value after the post back. I guess this means simple html control not getting saved in the view state of page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.