就是乱七八糟的东西放在一起!!
防止每次刷新/点击按钮时都对验证控件进行验证,把Button的CausesValidation属性设为false
构造函数没有返回值 不能用void /int等修饰
*.cs出现提示: Ctrl+J | Alt+→
Btton只有用鼠标点击时触发PostBack动作,即用Enter键时不触发该Button的PostBack动作
(焦点不会自动落到Button上)
UseSubmitBehavior属性置为:false
System.Text.RegularExpressions
System.Configuration.ConfigurationSettings.AppSettings["target"]
System.Configuration.ConfigurationManager.AppSettings["InfoRoleKey"]----recommend
System.Configuration.ConfigurationSettings.GetConfig("AX");
System.Web.HttpContext.Current;
System.Web.HttpContext.Current.Cache;
System.Web.HttpContext.Current.Session.Timeout
System.Reflection.Assembly
System.Web.HttpContext.Current ------------ -------------------//class 中使用Session
System.IO.Path.GetFileName
非Page用到Response
HttpResponse Response = HttpContext.Current.Response;
①script最好不要超过2000行
②你会做,并不意味这你应该做.(已方便用户为主)
③安全性:XHR必须包含URL,恶意用户可能会修改网站
可以察看源代码.
④XMLHttpRequest/远程脚本
⑤增加<tr>元素:将<tr>元素增加到表的<tbody>元素中
⑥设置class属性:<element>.style.cssText="font-weight:body";
代码片段:Tab Tab
重构:
①提取方法
②重命名
③提取接口
④将局部变量提升为参数
⑤移除参数
⑥重新排列参数
⑦封装字段
类设计器
VS2005新特征:
①Tab可以拖拽
②网站项目*.cs没有命名空间
③Debug有所增强
通过【即时窗口】改变当前要执行的语句
换算时间
正则表达式
二分查找
递归
装箱/拆箱
读写文件
通发??
二级域名怎么配置的??
< <
> >
& &
' '
" "
文件完整路径的正则表达式(包括网络路径): (([\w]+:)+\\|(\\\\))([^\/\\\"<>|:]+\\*)* 【RegexBuddy辅助完成】
不包含字符串:^AX_(?!zhz)[\w]+$ AX_zh能Match上.
.cs 的public var can be invoke by JS direct
DataTable转换为XML
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
System.IO.StringWriter strWriter = new System.IO.StringWriter();
System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriterXmlTextWriter(strWriter);
dt.WriteXml(xmlWriter);
string s = strWriter.ToString();
判断上传文件的类型是否为 *.xml 类型
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
//Method 1:simple process
Path.GetExtension(fileUpTool.FileName.Trim()).ToLower() != ".xml"
//Method 2:strict process
fileUpTool.PostedFile.ContentType != "text/xml"
后台输出WebControl变量,供JS脚本使用(WebControl.ClientID)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
protected void Page_Load(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
Response.Write("<script language='javascript'>");
Response.Write("var txtAX = '" + this.txtAX.ClientID + "';");
Response.Write("</script>");
}
获取当前登录用户
this.Request.LogonUserIdentity.Name
过滤DataTable
ds.Tables[0].Select("UserName='AX'", "PWD DESC");
foreach语句 //DropDownList 同 ListBox (每个Item包含Text/Value对)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
foreach (ListItem item in ListBox1.Items)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//---------------------------------------
foreach ( DictionaryEntry de in myHT )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
string key=de.Key;
string value=de.Value;
}
判断文件是否存在
File.Exist()也可以,
if (!System.IO.Directory.Exists(@"C:\AX.txt")
WinForm窗体重新画一遍
Application.DoEvents();
只有Repeater有RepeaterColumn属性(控制每行显示多少次循环)
<asp:DataList id="DataList1" runat="server" RepeatColumns="10"></asp:DataList>
对绑定的参数操作及传递多个参数(<asp:Image id="Image1" runat="server"></asp:Image>不能传递绑定的参数):
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Text='<%
#DataBinder.Eval(Container.DataItem,"type").ToString()=="0"?"改为多选":"改为单选"%>'
2
<IMG alt="" src="Chart.aspx?subject=<%#Server.UrlEncode(subject)%>&QID=<%#QID%>" align=middle>
正则表达式替换:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
string URL = "[URL=http://www.sina.com.cn]sina[/URL]直接复制地址就可以[URL=http://www.sohu.com]sohu[/URL]afdsafsadf[URL=http://www.163.com]163[/URL]";
URL = System.Text.RegularExpressions.Regex.Replace(URL, @"[[]URL=(?<urlValue>(.*?))[]](?<urlText>(.*?))[[]/URL[]]", "<a href='${urlValue}' target=_blank>${urlText}</a>");
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
string AX = "abcdzhz";
AX = System.Text.RegularExpressions.Regex.Replace(AX, "abc|abcd", "AX");
//输出【AXdzhz】,即发现匹配后马上替换.
Response.Write(AX);
客户端IP及来自的网页
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.SessionState;
8
using System.Web.UI;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.HtmlControls;
11![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
namespace ClientIP
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
14![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
15
/// WebForm1 的摘要说明。
16
/// </summary>
17
public class WebForm1 : System.Web.UI.Page
18![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
19
20
private void Page_Load(object sender, System.EventArgs e)
21![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22
// 在此处放置用户代码以初始化页面
23
if(!this.IsPostBack)
24![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
25
Response.Write("<br>用户IP:"+Request.UserHostAddress);
26
Response.Write("<br>用户IP:"+Request.ServerVariables["remote_addr"]);
27
Response.Write("<br>主机IP:"+Request.Url.Host);
28
Response.Write("<br>文件名:"+System.IO.Path.GetFileName(Request.Url.PathAndQuery));
29
Response.Write("<br>扩展名:"+System.IO.Path.GetExtension(Request.Url.PathAndQuery));
30
Response.Write("<br>上一个网页:"+Request.UrlReferrer);
31
}
32
}
33![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
35
override protected void OnInit(EventArgs e)
36![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
37
//
38
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
39
//
40
InitializeComponent();
41
base.OnInit(e);
42
}
43
44![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
45
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
46
/// 此方法的内容。
47
/// </summary>
48
private void InitializeComponent()
49![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
50
this.Load += new System.EventHandler(this.Page_Load);
51![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
}
53
#endregion
54
}
55
}
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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Made by AX</title>
<script language="javascript">
<!--
function ShowAD()
{
var ADString=GetAD();
var ADs=ADString.split("|");
var tr=document.createElement("<TR>");
for(var i=0;i<ADs.length;i++)
{
var AD=ADs[i].split(";");
var td=document.createElement("<TD>");
var a=document.createElement("<A target=_blank>");
a.href=AD[0];
a.innerHTML=AD[1];
td.appendChild(a);
tr.appendChild(td);
}
var tabElement=document.getElementById("tabAD");
var tbody=document.createElement("tbody");
tabElement.appendChild(tbody);
tbody.appendChild(tr);
}
function GetAD()
{
var ADString="http://www.163.com;网易|http://www.baidu.com;百度|http://www.sina.com;新浪";
return ADString;
}
//-->
</script>
</head>
<body onload="ShowAD();">
<table id="tabAD" width='400px' border='1' cellpadding='1' cellspacing='5'>
</table>
<br><br><br>
<div>①创建Element可以加<>,也可以不加,还可以带属性,<a target="_blank"><br>
②添加Element<br>
<ul><li>node.insertBefore(newChild,refChild):在refChild前插入子结点</li>
<li>node.appendChild(newChild);子结点插入到最后面</li>
<li>node.replaceChild(newChild,oldChild):替换子结点</li>
</ul>
③注意tbody<div/>
</body>
</html>
URL重定向完美版:(可扩展为根据host重定向)
①Global.asax.cs
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
protected void Application_BeginRequest(Object sender, EventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
string target,regular;
4
//URL主机头后面部分
5
string url=Request.Url.PathAndQuery.ToLower();
6
//禁止在URL中输入参数
7
if(url.IndexOf('?')!=-1)
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
9
url=url.Substring(0,url.IndexOf('?'));
10
}
11
//有多少条规则
12
int count=System.Configuration.ConfigurationSettings.AppSettings.Count;
13
//循环遍历匹配规则
14
for(int i=0;i<count;i++)
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16
//从Web.config里取出规则和符合规则的对应路径
17
target=System.Configuration.ConfigurationSettings.AppSettings.Keys[i].ToLower();
18
regular="^"+System.Configuration.ConfigurationSettings.AppSettings.GetValues(i)[0]+"$";
19
//替换参数
20
string Target=System.Text.RegularExpressions.Regex.Replace(url,regular,target);
21
if(Target!=url)
22![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
23
HttpContext.Current.RewritePath(Target);
24
break;
25
}
26
}
27
28![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
// //循环遍历匹配规则(感觉没有上面的性能好,但测测时间都是零,即二者的差别可以忽略不计,
32
// //也就不深究是Match()方法还是比较字符串是否相等性能好了,但上面的少一行代码)
33
// for(int i=0;i<count;i++)
34
// {
35
// //从Web.config里取出规则和符合规则的对应路径
36
// target=System.Configuration.ConfigurationSettings.AppSettings.Keys[i].ToLower();
37
// regular="^"+System.Configuration.ConfigurationSettings.AppSettings.GetValues(i)[0]+"$";
38
// //进行匹配
39
// System.Text.RegularExpressions.Match match=System.Text.RegularExpressions.Regex.Match(url,regular);
40
// //如匹配成功
41
// if(match.Length>0)
42
// {
43
// //替换参数
44
// target=System.Text.RegularExpressions.Regex.Replace(url,regular,target);
45
// HttpContext.Current.RewritePath(target);
46
// //跳出循环
47
// break;
48
// }
49
// }
50
}②Web.config
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
<appSettings>
2
<!--真(key):假(value)-->
3
<!--真:真实路径以【~/】表示根路径-->
4
<!--假:与用户输入的主机头以后的部分进行完全匹配-->
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
<!--key不要有重复,否则后果很严重-->
7
<!--使用前请学习一些基本的正则表达式常识-->
8
<!--必须保证实际的路径与规则不匹配,否则会按规则转向-->
9
<!--value中最好不要嵌套括号,也许会发生一些神奇的事件-->
10
<!--如果想带参数,一个【$*】对应一个【()】,其中*从1开始-->
11
<!--指定扩展名【.ax,.whw,.htm等】需要在IIS里配置后才可使用-->
12
<!--参数间的【&】用【&】替换,同理,其它特殊字符也要替换-->
13
<!--规则从上至下执行,如有重合的地方,以第一个匹配上的规则为准-->
14
<!--页面提交会以当前地址栏的URL+真实页面+参数形式提交,请深入学习正则表达式-->
15
<!--请不要怀疑本功能,如果出错,一定是你的错,一般是正则表达式的问题,禁止修改Global-->
16
<!--不会配置扩展名,每人/次培训费¥10RMB,免费热线:800-110,包学包会,不会下期免费再学-->
17
<!--Whw+AXzhz Made in China-->
18
<add key="~/test/AX.aspx?id=$1" value="/product/(\d+)\.htm"></add>
19
<add key="~/test/AX.aspx?id=$1&name=$2&name=$3" value="/(\d{2})/(\d{1})/(\d{1})/[A-Za-z]*\.(htm|aspx)"></add>
20
<add key="~/test/AX.aspx?id=$1&name=$2&name=$3&name=$4" value="/(\d{1})/(\d{1})/(\d{1})/(([A-Za-z0-9])*)\.(htm|aspx)"></add>
21
<add key="~/TT/WebForm1.aspx" value="/a*\.htm"></add>
22
<add key="~/test/AX.aspx?id1=$1" value="/(\d+)\.htm"></add>
23
<add key="~/test/AX.aspx?id3=$1" value="/3.htm"></add>
24
<add key="~/TT/WebForm1.aspx" value="/45*\.aspx"></add>
25
</appSettings>字符串倒置(以前总笔试总也不敢确定,今天终于测试了一下,OK)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
string s="hello_XA";
2
string ss="";
3
for(int i=s.Length-1;i>=0;i--)
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
5
ss+=s[i];
6
}
7
Response.Write(ss); 添加序号/编号
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
private void rpShow_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
//怎么序号不对???????????------------------------------------------------------------------------------------------
4
if(e.Item.ItemIndex!=-1)
5![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
6
serialNum=e.Item.ItemIndex+2;
7
}
8
// if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
9
// {
10
// serialNum++;
11
// }
12
} 添加删除提示
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
private void dlShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
//添加删除确认
4
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
5![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
6
iNumQuestion++;
7
LinkButton lbt=(LinkButton)e.Item.FindControl("lbtnDel");
8
lbt.Attributes.Add("onclick","return confirm('确认要删除纪录吗?')");
9
}
10
} 类似Windows的长随即不重复字符串
Guid g = Guid.NewGuid(); CSS Style
<div style="overflow-x: auto; overflow-y: scroll; height: 225px; width: 675px; text-align:left"
id="divFindApplicationContainer" class="WrapperDiv2" runat="server">
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
.TextOverflow
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}{
overflow: Hidden;
Text-Overflow: Ellipsis;
white-space:nowrap;
}
DataTable添加另一个Table的一行
dtNew_AX.Rows.Add(dtOld_AX.Rows[0].ItemArray);
页面加载完后Show Alert
Page.RegisterStartupScript("AX", "<script>alert('" + alertMessage_AX + "');</script>"); 通过IP地址找到机器名
ping -a 172.25.0.1
限制HttpRequest的时间和数据大小时间太小有可能会报这个异常:
Type 'System.Web.HttpApplication+CancelModuleException' in assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
<system.web>
<!--executeTime:单位(″) maxRequestLength:单位(KB)-->
<httpRuntime executionTimeout="20" maxRequestLength="8192" />
</system.web> TreeView的Node不做PostBack
new TreeNode().SelectAction = TreeNodeSelectAction.None;
博客园→
斧头帮少帮主