ASP.Net学习笔记002--ASP.Net服务端控件做了什么2
以前写的课程都没有附上源码,很抱歉!
课程中的源码可以加qq索要:1606841559
技术交流qq1群:251572072
技术交流qq2群:170933152
也可以自己下载:
ASP.Net学习笔记002ASP.Net服务端控件做了什么2.zip
http://credream.7958.com/down_20144361.html
1.程序结构
项目中:
WebForm1.aspx下有两个文件:
WebForm1.aspx中代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
//原来的html代码也可以和asp.net引擎中的控件写到一起
// <input type ="button;" name ="" />
//1.注意这里的button;后需要加引号,否则会出现由于xml规则引起的警告
//2.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</form>
</body>
</html>
------------------------------------------------------
<input id ="abc" type="Button" value ="tuzhu" runat="server" />
<!--
1.runat="server"有这句的是服务器控件,没这句的是html控件
-->
-------------------------------------------------------------------
WebForm1.aspx.cs用于写逻辑
WebForm1.aspx.designer.cs
-----------------------------------------------------------
上课中的例子,asp.net引擎会自动生成如下html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="WebForm1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODcwNjAxNTI1ZGRiIB7rVQurxN6PSjZOEyCrkP00D6r1puuxdi+HAKhLLw==" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBQLu3v3PDALs0bLrBgLs0fbZDAKM54rGBgLs0Yq1BZ6QsF/eCv2iwBXy0TytLvnomEZFJdI8yJ+PesYxhzgI" />
</div>
<div>
</div>
<input name="TextBox1" type="text" value="2" id="TextBox1" />
<input name="TextBox2" type="text" value="3" id="TextBox2" />
<input type="submit" name="Button1" value="Button" id="Button1" />
<input name="TextBox3" type="text" value="5" id="TextBox3" />
</form>
</body>
</html>
-------------------------------------------------------------------
ASP.Net中可以写入原生态的html和JavaScript
比如:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebForm.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script src ="Scripts/jquery-1.4.1.min.js" type="text/javascript" ></script>
<script type ="text/javascript" language ="javascript" >
$(function () {
$("#TextBox3").mouseover(function () {
$(this).css("color", "Red");
});
});
</script>
<div>
</div>
<!-- <input id ="abc" type="Button" value ="tuzhu" runat="server" />
1.runat="server"有这句的是服务器控件,没这句的是html控件
服务器控件,服务器控件可以在代码中.出来
<asp:Button ID ="MyControl" runat ="server" />
1.asp.net控件也可以自己写
-->
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</form>
</body>
</html>
------------------------------------------------------------------