怎样用.net2.0做网站
1,根据需求ps出网站模板,切割图片。
2,保存到dw中,画层。
3,到vs中,建母版页,在层里放入ContentPlaceHolder,创建内容页。
4,所有编辑代码在内容页ContentPlaceHolder里写。页面缓存代码<%@ OutputCache Duration="5" VaryByParam="*" %>
其中,在母版页的div标签必须放在runt=server里
5,编写js以及css文件导入<!--导入js -->
<script type="text/javascript" src="js/JScript.js"></script>和<link href="css/CSS.css" type="text/css" rel="stylesheet" />
6,数据整体显示用GridView 数据自己设计,自定义用datalist,数据的精确显示用repether
7,imageButton中,要加入图片路径要和aspx中的路径调用一样,比如为../images/ajax-loader.gif 则我们要写成images/ajax-loader
8,imageButton没有onmouserover和onmouserout事件 必须写js代码写 写后在onload调用如下: imgLogin.Attributes.Add("onmouseover", "Javascript:ChangeImg(this,'images/loginout.png');");
imgLogin.Attributes.Add("onmouseout", "Javascript:ChangeImg(this,'images/loginover.png');");
imgRegister.Attributes.Add("onmouseover", "Javascript:ChangeImg(this,'images/registerout.png');");
imgRegister.Attributes.Add("onmouseout", "Javascript:ChangeImg(this,'images/registerover.png');");将进程休眠代码:System.Threading.Thread.Sleep(3000);
9,
注册ajax在内容页的层ContentPlaceHolder里
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlBagua" runat="server" >
<ItemTemplate>
<table>
<tr>
<td>
<a href="content.aspx?bid=<%#Eval("bID") %>" title="<%# Eval("bTitle")%>">
<span style="font-size:12px;">
<%# getCut(Eval("bTitle").ToString()) %>
</span>
</a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:Label ID="lblCurrentPage" runat="server" Style="left: 4px; position: relative;
top: 1px;font-size:14px;" Text="Label"></asp:Label>
<asp:Button ID="btnPrev" runat="server" Style="left: 17px; position: relative; top: 5px"
Text="上一页" OnClick="btnPrev_Click" />
<asp:Button ID="btnNext" runat="server" Style="left: 12px; position: relative; top: 5px"
Text="下一页" OnClick="btnNext_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
10.asp.net2.0版本.cs文件放在App_Code里 新建文件添加ASP.NET文件App_Code
11.数据库access放入App_data里
12.access数据库连接字符串OleDbConnection myConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\taobao.mdb");
string connectionString = myConn.ConnectionString;
13.各层添加引用 Models BLL DAL
新建网站保存到web里 删了工作空间的.sln文件 重新生成解决方案,放到web同一目录
三层结构保存到web同一目录
14.select top 6 * from >>>>>
15,自己的一个用户自定义登陆控件:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserLoginControl.ascx.cs" Inherits="_Controls_UserLoginControl" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate> <asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="images/ajax-loader.gif" alt="" /><span style="font-size: 10pt; color: #ff6666; font-family: 楷体"><strong><span
style="color: #00ff33">请 稍 等..</span>.
</strong>
</span>
</ProgressTemplate>
</asp:UpdateProgress>
<div id="divlogin" runat="server">
<asp:Label ID="lblName" runat="server" Style="left: -5px; position: relative; top: -4px"
Text="用户名:" Height="11px" Width="73px" Font-Bold="True" Font-Names="楷体" Font-Size="Small" ForeColor="#FF8000"></asp:Label><asp:TextBox ID="txtName" runat="server" Style="left: -26px; position: relative;
top: 1px" Width="116px"></asp:TextBox>
<asp:Label ID="lblPwd" runat="server" Style="left: -26px; position: relative; top: -5px"
Text="密 码:" Height="11px" Width="71px" Font-Bold="True" Font-Names="楷体" Font-Size="Small" ForeColor="#FF8000"></asp:Label><asp:TextBox ID="txtPwd" runat="server" Style="left: -51px; position: relative;
top: 2px" Width="116px" TextMode="Password"></asp:TextBox>
<asp:ImageButton ID="imgLogin" runat="server" ImageUrl="../images/loginover.png" style="position: relative; left: 354px; top: -30px;" OnClick="imgLogin_Click"/>
<asp:ImageButton ID="imgRegister" runat="server" ImageUrl="../images/registerover.png" style="left: 401px; position: relative; top: -30px"/>
</div>
<div id="divmessage" runat="server" style="display:none">
<asp:Label ID="lblmessage" runat="server" style="left: -8px; position: relative; top: -7px" Font-Bold="True" Font-Names="汉仪萝卜体简" ForeColor="#FF8000" ></asp:Label>
</div>
<div id="divvalidate" runat="server" style="display:none">
<asp:Label ID="lblvalidate" runat="server" Height="16px" Style="left: 0px; position: relative;
top: -55px" Text="Label" Width="215px" Font-Bold="True" Font-Names="楷体" Font-Size="Small" ForeColor="Red"></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>页面调用如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Src="_Controls/UserLoginControl.ascx" TagName="UserLoginControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<htmlhttp://www.w3.org/1999/xhtml" target=_blank>http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<!--导入js -->
<script type="text/javascript" src="js/JScript.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<uc1:UserLoginControl ID="UserLoginControl1" runat="server" />
</form>
</body></html>
16,页面导入用户控件时候,如果页面有scriptManager则自定义控件页面不需要加scriptManager 如果页面没有scriptManger则用户自定义控件需要加scriptManager
17,imagebutton事件丢了,不响应click:
在页面存在验证控件的时候,如果按键(如button,imagebutton等)设置不当有可能出现事件丢失的问题,即单击按键的时候页面没有反应。这是由于此类按键有一个CausesValidation的属性,该属性设置是否导致激发验证,默认设置为true,采用默认设置就有可能导致验证失败,从而无法正常激发按键的事件,将此属性设为false即可。
18.updateprogress里的信息可以放到层里显示在不同的位置。
19,datelist获值如:myUser.UArea = this.DropDownList1.SelectedItem.Text;
20,向access数据库放入日期时,因为和access数据库的日期类型不同
所以代码如下
// OleDbParameter parameter = new OleDbParameter();
// parameter.OleDbType = OleDbType.DBDate;
// parameter.Value = DateTime.Now.ToLocalTime(); 21,在做rss新闻自动收集到我们的页面时候,我们用的页面代码是
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rss.aspx.cs" Inherits="rss" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<htmlhttp://www.w3.org/1999/xhtml" target=_blank>http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li>标题:<a href='<%# Eval("link") %>'><%# Eval("title") %></a>
时间:<%# Eval("pubDate")%>
<hr />
</ItemTemplate>
<FooterTemplate> </ul></FooterTemplate>
</asp:Repeater>
</form></body>
</html>
后台代码是:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;
using System.Xml.Linq;public partial class rss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//RSS源
XDocument doc = XDocument.Load("http://www.cnblogs.com/rss
//取item下的元素值
var query =from p in doc.Descendants("item")
select new
{
title = p.Element("title").Value,
link = p.Element("link").Value,
pubDate=p.Element("pubDate").Value
};
Repeater1.DataSource = query;
Repeater1.DataBind(); }
}
其中要导入引用system.linq system.xml.linq 先添加程序集 code的但是我们用的是vs2005而linq支持的是2008 所以不能用
于是用的代码是:
<html>
<head>
<title>Ajax 读取RSS示例</title><script type="text/javascript">
var xmlHttp=false;
function createXMLHttpRequest() {try{xmlHttp=new XMLHttpRequest();}
catch(e)
{
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e2)
{try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e3){xmlHttp=false;}
}
}
if(!xmlHttp){alert("您的浏览器不支持XMLHTTP对象,初始化失败!");}
}function readRSS(url) {
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
ResultSet();}
}
}function ResultSet() {
document.getElementById("result").innerHTML="";
var results = xmlHttp.responseXML;
var title = null;
var item = null;
var link=null;
var enclosure="";
//得到channel
var ccc=results.getElementsByTagName("channel");
var headtitle=ccc[0].getElementsByTagName("title")[0].firstChild.nodeValue;
var headlink=ccc[0].getElementsByTagName("link")[0].firstChild.nodeValue;
var cell = document.createElement("div");
cell.innerHTML="<h1><a href="+headlink+" target=_blank>"+headtitle+"</a></h1><br>";
document.getElementById("result").appendChild(cell);
//得到items
var items = results.getElementsByTagName("item");
for(var i = 0; i < items.length-4; i++) {
item = items[i];
link=item.getElementsByTagName("link")[0].firstChild.nodeValue;
title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
description=item.getElementsByTagName("description")[0].firstChild.nodeValue;
try{
enclosure=item.getElementsByTagName("enclosure")[0].getAttribute("url");
if(enclosure!==""){enclosure="<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0 width=500 height=500><param name=movie value="+enclosure+"><param name=quality value=high><embed src="+enclosure+" quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=100% height=100% ></embed></object>";}
}
catch(e){}
var cell = document.createElement("div");
cell.innerHTML="<a href="+link+" target=_blank>"+title+"</a>|[<a style='cursor: default;' onclick='javascript:if(document.getElementById(\"msg"+i+"\").style.display==\"none\"){this.innerHTML=\"关闭\";document.getElementById(\"msg"+i+"\").style.display=\"\";}else{this.innerHTML=\"预览\";document.getElementById(\"msg"+i+"\").style.display=\"none\";}'>预览</a>]<div id='msg"+i+"' style='display:none;'>"+description+"<div>"+enclosure+"</div><hr></div>";document.getElementById("result").appendChild(cell);
}
}
function readrss1()
{
varhttp://rss.sina.com.cn/news/society/focus15.xml" target=_blank>http://rss.sina.com.cn/news/society/focus15.xml";
readRSS(url);
}</script>
</head>
<body onload="readrss1()">
<div id="result"></div>
</body>
</html>
静态的页面不错啊 呵呵22,但是不显示,可能代码冲突所以我用了
iframe src="rss.html" style="background-color: transparent; width: 232px; height: 233px;" frameborder="0" ></iframe>
23,自动发邮件给注册用户的代码要在web.xml配置;
<system.net>
<mailSettings>
<smtp deliveryMethod="Network"mailto:gqtaobao@qq.com" target=_blank>gqtaobao@qq.com">
<network host="smtp.qq.com" port="25" userName="gqtaobao" password="gqtaobao" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>建一个页面veryfycode.aspx后台代码如下
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class _Controls_VerifyCode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ VerifyCode v = new VerifyCode();
v.Length = this.length;
v.FontSize = this.fontSize;
v.Chaos = this.chaos;
v.BackgroundColor = this.backgroundColor;
v.ChaosColor = this.chaosColor;
v.CodeSerial = this.codeSerial;
v.Colors = this.colors;
v.Fonts = this.fonts;
v.Padding = this.padding;
string code = v.CreateVerifyCode(); //取随机码
v.CreateImageOnPage(code, this.Context); // 输出图片 Response.Cookies.Add(new HttpCookie("CheckCode", code.ToUpper()));// 使用Cookies取验证码的值
}
#region 验证码长度(默认6个验证码的长度)
int length =4;
public int Length
{
get {return length; }
set{ length = value; }
}
#endregion #region 验证码字体大小(为了显示扭曲效果,默认40像素,可以自行修改)
int fontSize =20;
public int FontSize
{
get{ return fontSize; }
set{ fontSize = value; }
}
#endregion #region 边框补(默认1像素)
int padding = 2;
public int Padding
{
get{ return padding; }
set{ padding = value; }
}
#endregion
#region 是否输出燥点(默认不输出)
bool chaos = true;
public bool Chaos
{
get{ return chaos; }
set{ chaos = value; }
}
#endregion
#region 输出燥点的颜色(默认灰色)
Color chaosColor = Color.LightGray;
public Color ChaosColor
{
get{ return chaosColor; }
set{ chaosColor = value; }
}
#endregion #region 自定义背景色(默认白色)
Color backgroundColor = Color.White;
public Color BackgroundColor
{
get{ return backgroundColor; }
set{ backgroundColor = value; }
}
#endregion #region 自定义随机颜色数组
Color[] colors ={Color.Black,Color.Red,Color.DarkBlue,Color.Green,Color.Orange,Color.Brown,Color.DarkCyan,Color.Purple};
public Color[] Colors
{
get{ return colors; }
set{ colors = value; }
}
#endregion #region 自定义字体数组
string[] fonts ={"Arial", "Georgia"};
public string[] Fonts
{
get{ return fonts; }
set{ fonts = value; }
}
#endregion #region 自定义随机码字符串序列(使用逗号分隔)
string codeSerial = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
public string CodeSerial
{
get{ return codeSerial; }
set{ codeSerial = value; }
}
#endregion
}另一个调用的页面代码是:
<div style="left: 128px; width: 252px; position: relative; top: 139px; height: 1px">
<img id="imgVerify" src="VerifyCode.aspx?" alt="看不清?点击更换" onclick="this.src=this.src+'?'" />
<asp:TextBox ID="txtcode" runat="server" ToolTip="验证码不区分大小写" Width="96px"></asp:TextBox>
<asp:Label ID="lblcode" runat="server" style="position: relative" Font-Size="Small" ForeColor="Red"></asp:Label>24,在做网站时,我把网站上传到虚拟空间后发现我做的用户控件-注册控件不能隐藏查了又查,在我的本机能用的啊 ,以为空间商不支持ajaxtoolkit问了说支持 ,才发现sys错误,未定义,于是查了个错误的方法却没有用如下:
“当需要身份验证时,未登录前,对web站点的任何文件的访问都将被拒绝。 而一般的网站都有一部分页面是不需要身份证验的,如:首页,新闻页面,登录页面,等等。 所以,网站的Sys未定义错误就出现了。将 axd文件定义为无需验证后,该错误彻底解决。
<location path="ScriptResource.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
”其实没作用了还是:
网页错误详细信息
用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; QQDownload 563; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729)
时间戳: Wed, 12 Aug 2009 03:03:15 UTC
消息: 'Sys' 未定义
行: 64
字符: 1
代码: 0
URI: http://www.gqtaobao.com/
消息: 'Sys' 未定义
行: 1411
字符: 178
代码: 0
URI: http://www.gqtaobao.com/
消息: 'Sys' 未定义
行: 1434
字符: 1
没用:
哎 重装了aspajaxstep没用
告终。
哎
继续
最后 空间商不支持ajax
告终
24.关于网页图层的问题
可以以表格或者单元格为对象
比如
<td colspan="18" style="position:relative;">
<div id="Layer1" style="left: 4px; top: 34px; table-layout: auto;position:absolute;" onclick="return Layer1_onclick()"><asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder></div>
<div id="Layer2" style="left: 245px; top: 4px;"><asp:contentplaceholder id="ContentPlaceHolder2" runat="server">
</asp:contentplaceholder></div>
<div id="Layer3" style="left: 536px; top: 42px"><asp:contentplaceholder id="ContentPlaceHolder3" runat="server">
</asp:contentplaceholder></div>
<div id="Layer4" style="left: 21px; top: 304px"><asp:contentplaceholder id="ContentPlaceHolder4" runat="server">
</asp:contentplaceholder></div>
<div id="Layer5" style="left: 1px; top: 505px"><asp:contentplaceholder id="ContentPlaceHolder5" runat="server">
</asp:contentplaceholder></div>
<div id="Layer6" style="left: 228px; top: 505px"><asp:contentplaceholder id="ContentPlaceHolder6" runat="server">
</asp:contentplaceholder></div>
<div id="Layer7" style="left: 474px; top: 507px"><asp:contentplaceholder id="ContentPlaceHolder7" runat="server">
</asp:contentplaceholder></div>
<div id="Layer8" style="left: 715px; top: 506px"><asp:contentplaceholder id="ContentPlaceHolder8" runat="server">
</asp:contentplaceholder></div>
<div id="Layer9" style="left: 4px; top: 856px"><asp:contentplaceholder id="ContentPlaceHolder9" runat="server">
</asp:contentplaceholder></div>
<div id="Layer10" style="left: 479px; top: 856px"><asp:contentplaceholder id="ContentPlaceHolder10" runat="server">
</asp:contentplaceholder></div>
<img src="images/index_09.gif" width="950" height="1104" alt=""/></td>
<td>
25.知识
background: 是背景颜色
enabled:可选项。布尔值(Boolean)。设置或检索滤镜是否激活。true | false
true:默认值。滤镜激活。
false:滤镜被禁止。
style:可选项。整数值(Integer)。设置或检索透明渐变的样式。0 | 1 | 2 | 3
0:默认值。整体透明度。将 Opacity 值均匀的作用于对象。
1:线性渐变透明度。从由 StartX 和 StartY 决定的点,由 Opacity 决定的透明度开始,到由 FinishX 和 FinishY 决定的点,由 FinishOpacity 决定的透明度结束。
2:圆形放射渐变透明度。圆形放射区域的圆心为对象的中心,圆周到与对象的边相切为止。透明渐变由圆心开始,到圆周结束。开始透明度由 Opacity 决定,结束透明度由 FinishOpacity 决定。
3:矩形放射渐变透明度。由对象的边开始,到对象的中心结束。开始透明度由 Opacity 决定,结束透明度由 FinishOpacity 决定。
opacity:可选项。整数值(Integer)。设置或检索透明渐变的开始透明度。取值范围为 0 - 100 。默认值为 0 ,即完全透明。 100 为完全不透明。
finishOpacity:可选项。整数值(Integer)。设置或检索透明渐变的结束透明度。取值范围为 0 - 100 。默认值为 0 ,即完全透明。 100 为完全不透明。
startX:可选项。整数值(Integer)。设置或检索透明渐变开始点的水平坐标。其数值作为对象宽度的百分比值处理。默认值为 0 。
startY:可选项。整数值(Integer)。设置或检索透明渐变开始点的垂直坐标。其数值作为对象高度的百分比值处理。默认值为 0 。
finishX:可选项。整数值(Integer)。设置或检索透明渐变结束点的水平坐标。其数值作为对象宽度的百分比值处理。默认值为 0 。
finishY:可选项。整数值(Integer)。设置或检索透明渐变结束点的垂直坐标。其数值作为对象高度的百分比值处理。默认值为 0 。
26。发邮件
jmail.Message jmessage = new jmail.MessageClass();
jmessage.Charset = "GB2312";
jmessage.From = "496330130@qq.com";
jmessage.FromName = "496330130";
jmessage.ReplyTo = "496330130@qq.com";
jmessage.Subject = "观前淘宝网感谢您的注册!";
jmessage.AddRecipient("496330130@qq.com", "496330130", "*******");
jmessage.Body = "您的用户名是:"+this.txtRegisterName.Text+" 密码是:"+this.txtRegisterPwd.Text+" 点击这里http://www.gqtaobao.com/进行跳转登陆";
jmessage.MailServerUserName = "496330130";
jmessage.MailServerPassWord = "*******";
jmessage.Send("smtp.qq.com", false);
jmessage.Close();
代码可以以那个 到邮箱设置支持stmp
浙公网安备 33010602011771号