更新时间:2023-12-06 09:58:28
首先,如果像示例中那样将Html控件从工具箱"拖到设计图面上,则创建的标记不包含runat ="server".这意味着它是本地HTML标记,而不是.NET控件.没有runat ="server"的本地Html标记没有服务器端功能.因此,您无法在后面的代码中设置"Text1"输入标签的值.
First, if you drag an Html control from the Toolbox onto your design surface as in your example, the tag created does not include runat="server". That means it is native Html tag and not a .NET control. A native Html tag without the runat="server" has no server-side functionality. Thus, you could not set the value of the your "Text1" input tag in the code-behind.
第二,将runat ="server"添加到Html输入标记后,将其从本地Html标记转换为从System.Web.UI.Control派生的HtmlControl.现在,该问题可能会演变为从System.Web.UI.Control和System.Web.UI.WebControl派生的内容之间的差异.但是,为了专门解决您的问题,让我们将标准输入type ="text"控件与TextBox控件进行比较:
Second, once you add the runat="server" to your Html input tag, you convert it from a native Html tag into a HtmlControl which derives from System.Web.UI.Control. Now the question could morph into the differences between something that derives from System.Web.UI.Control and System.Web.UI.WebControl. However, to specifically address your question, let's compare a standard input type="text" control to the TextBox control:
现在,所有这些都说明了,如果您不需要任何WebControl功能,那么使用本机的Html控件将更加精简.在您的示例中,您只需将两个空控件拖到设计图面上.如果这是您所需要的,那么使用.NET控件将是多余的.但是,随着您开始添加AutoComplete和服务器端事件等,浏览器获得的全部内容,Javascript以及所有内容都变得更大了.
Now, all that said, if you do not need any of WebControl capabilities, then using an native Html control is substantially leaner. In your example, you simply dragged two empty controls onto your design surface. If that is all you needed then using the .NET control would be overkill. However, as you start adding AutoComplete and server-side events and such, the full content, Javascript and all, of what gets to the Browser is much larger.