全速加载中

asp.net学习笔记·html服务器端控件的使用

  • 不要在控件属性中写<%%>
  • 可以在js代码中书写
举例:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<script type="text/javascript">
document.getElementById("<%=TextBox1.ClientID %>").onmouseover = function () {
document.getElementById("<%=TextBox1.ClientID %>").value = "你好";
</script>
  • 或者直接使用Html客户端控件,在JS中直接使用控件的id进行操作。不过这样在客户自定义控件中使用的时候,如果页面使用多个控件时会有错误,因为控件的ID可能会重复。最好是使用runat="server"。
  • 不需要在服务器端进行操作的时候使用html控件
  • 当控件没有在asp.net中封装的时候使用服务器端html控件,即在html中使用runat="server"进行属性设置
  • 当与服务器端进行大量交互的时候使用asp.net服务器控件,因为集成了大量的方法,方便

 

posted @ 2012-12-28 21:41  许鸿飞  阅读(210)  评论(0编辑  收藏  举报