[英]In asp.net what is the difference between using asp.net web control and simple html imput control
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. 在我的asp.net Web控件表单中,我使用两个文本框,第一个是简单输入html控件,第二个是asp.net输入Web控件。
<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. 我需要知道使用简单控件和asp.net输入控件有什么区别,它们都在表单提交后将值传递给代码。 can any one help me on this? 谁可以帮我这个事?
As defined in your example input type="text"
won't even be visible to code-behind because it is missing runat="server"
attribute. 正如您的示例中所定义的,由于缺少runat="server"
属性,因此代码隐藏甚至看不到input type="text"
。
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 (eg it has property .Text
vs. .Value
of an HtmlInput control, it has events and other properties). ASP.NET TextBox是更高级的,并且与其余ASP.NET模型相当(例如,它具有HtmlInput控件的.Text
与.Value
属性,它具有事件和其他属性)。
But if you simple need to pass text information back to the server, either of them will do the job. 但是,如果您仅需要将文本信息传递回服务器,则它们中的任何一个都可以完成工作。
The biggest differences are that 最大的不同是
The asp:Textbox renders HTML to the client/browser when the page request is made. 发出页面请求时,asp:Textbox会将HTML呈现到客户端/浏览器。 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. 将ASP.NET控件(在本例中为asp:TextBox)作为服务器端的代码,当向服务器发出对aspx页的请求时,该代码知道呈现<input type="text">
HTML元素。
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. ASP.NET编译器在解析aspx页面时,只会吐出您在Email:和Email2中使用的<input type="text">
HTML元素:由于runat =,ASP.NET编译器知道这是一个服务器控件。 “服务器”标签。 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" />
因此,具有对服务器上ASP.NET程序集的引用的ASP.NET编译器将读取<asp:TextBox>
的代码,并知道最终使用<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. 因此可以在后面的代码中访问,但<input>
元素则不可。 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. 此时,您可以在研究中考虑一下,如果将runat =“ server”添加到元素,则可以在后面的代码中访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.