HTML控件和ASP.NET Web控件 [英] Html control and asp.net web control

查看:50
本文介绍了HTML控件和ASP.NET Web控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道HTML控件之间到底有什么区别

i would like to know what exactly the difference between Html control

和asp.net Web控件.为什么我们需要这两种类型的控件?

and asp.net web control. why do we need these two types of controls?

我在我的网页上放置了一个html输入文本,html按钮和asp.net文本框以及ASP.NET按钮

i have placed one html input text ,html button and asp.net text box AND ASP.NET BUTTON on my web page

    <input id="Text1"    type="text" />

    <input id="Button2" type="button" value="button" />







    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" />

当我使用视图源时,两者的渲染方式相似

when i take view source, both are rendered similarly

    <input id="Text1"    type="text" />

    <input id="Button2" type="button" value="button" />




    <input name="TextBox1" type="text" id="TextBox1" />

    <input type="submit" name="Button1" value="Button" id="Button1" />

与html控件相比,Web控件的优点是什么.

what is the advantage of web control over html control.

我在互联网上有一些链接,但不清楚到底是什么

I got some links in the internet,but not clear what exactly

它们用于.

http://www.extremeexperts.com/Net/FAQ/DiffBetweenServerandHTMLControls.aspx.

任何人都可以解释这两个控件之间的区别.

Could any one please explain the difference between these two controls.

推荐答案

首先,如果像示例中那样将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:

  1. 可以从代码隐藏区访问TextBox控件,而输入控件不能(不容易)访问代码隐藏区,这也意味着您可以为TextBox控件连接服务器端事件,而不能使用标准的HTML控件.
  2. TextBox控件使用ViewState自动保存其值.
  3. 可以使用Theme和.skin文件对TextBox控件进行外观设置,而本机Html控件则不能.
  4. 根据其TextMode属性,TextBox可以将其呈现为输入type ="text"控件或文本区域.
  5. TextBox控件可以使用验证器参与验证.
  6. 最后但并非最不重要的是,如果需要,TextBox控件可以使用控件适配器在不同的浏览器中以不同的方式呈现.请参阅 http://msdn.microsoft.com/en-us/magazine/cc163543.aspx .

现在,所有这些都说明了,如果您不需要任何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.

这篇关于HTML控件和ASP.NET Web控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆