1。JavaScript。鼠标划过按钮文字变化。
<asp:Button id="Button1" runat="server" Text="hahaha" onmouseover="this.style.fontWeight='bold';"
onmouseout="this.style.fontWeight='normal'">
</asp:Button>
-----------------------------------------------------------------------
2。一个MessageBox问题。
方法一:
Response.Write("<script language=JavaScript>alert('这是客户端脚本')</script>");
-------
方法二:
<script language="JavaScript">
function client_func()
{
alert("这是客户端脚本");
}
</script>
Button1.Attributes.Add("onclick", "client_func()");
-------------------------------------------------------------------------
3。css样式
.css文件
***
table
{
font-family: verdana, arial;
font-size: 25pt;
font-weight:bold;
display: block;
}
****
html-Head文件描述:
****
<link href="danny.css" type="text/css" rel="stylesheet">
****
-----------------------------------------------------------------------
4。自定义验证
int i = args.Value.Length;
if (i > 8) args.IsValid = true;
else args.IsValid = false;
----------------------------------------------------------------------
5。小技巧
if (this.Page.IsValid)Response.Redirect("indexer.aspx");
6.
<div align="center"><a href="javascript:window.close()"><font size="2">关闭窗口</font></a>
<a href="javascript:self.close()">
7.
<marquee>21世纪将是科学技术飞速发展、充满机遇和挑战、更加激动人心的时代。</marquee>
<BODY bgcolor=ivory text=orange link=red alink= green vlink= blue >
8.计数器
<% Application.Lock();
Application["count"] =Convert.ToInt32(Application["count"]) + 1;
Application.UnLock(); %>
9.
IsPostBack
protected void Page_Load(object sender, EventArgs e)
{//利用IsPostBack属性控制页面初始化代码的加载
if (!this.IsPostBack)
{
Response.Write("<br>您是第一次加载此Web页!");
}
else
{
Response.Write("<br>您是第二次或更多次加载此Web页!");
}
Response.Write("<br>无论您是多少次加载此此Web页,均显示此行文字");
}
10.
private String PAGE_STATE = "页状态";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyUpdatePage(0);
}
}
protected void Button2_Click(object sender, EventArgs e)
{//下一页
int MyPageState = Convert.ToInt32(Request.Form[PAGE_STATE]);
MyPageState += 1;
MyUpdatePage(MyPageState);
}
protected void Button1_Click(object sender, EventArgs e)
{//上一页
int MyPageState= Convert.ToInt32(Request.Form[PAGE_STATE]);
MyPageState -= 1;
MyUpdatePage(MyPageState);
}
private void MyUpdatePage(int MyPageState)
{//保留信息
Label1.Text = MyPageState.ToString();
ClientScript.RegisterHiddenField(PAGE_STATE,MyPageState.ToString());
}
11.
protected void Page_Error(Object sender, EventArgs e)
{//管理不可预料的错误
String MyInfo= "<font face=verdana color=blue>"
+ "<h2>" + Request.Url.ToString() + "</h2>"
+ "<pre><font color=green>" + Server.GetLastError().ToString() + "</pre>"
+ "</font>";
Response.Write(MyInfo);
Server.ClearError();
}
12.String MyInfo = "alert('欢迎使用 Visual C# 2005');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "随便写点什么", MyInfo, true);
13.
<!--#Include File="MyCopyRight.aspx" -->
14.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx" Target="_blank"
Width="210px">转到第二页(打开一个新窗口)</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Default2.aspx" Target="_parent"
Width="206px">转到第二页(在父窗口中打开)</asp:HyperLink>
15.
this.Button1.Attributes.Add("OnClick", "window.open(document.location,'big', 'fullscreen=yes')");
this.Button2.Attributes.Add("OnClick", "window.close();");
16. Response.Write("<br>远程客户端的IP主机地址:"+Request.UserHostAddress);
Response.Write("<br>远程客户端的 DNS 名称:" + Request.UserHostName);
17.css
<link rel="stylesheet" type="text/css" href="StyleSheet.css">
//StyleSheet.css
body
{
}
.labelstyle
{
z-index: 102;
left: 344px;
position: absolute;
top: 60px;
font: 12pt 宋体;
font-size:x-large;
color:red;
}
.inputstyle
{
font: 14pt 宋体;
border-style:solid;
border-color:green;
width:200;
}
.selectstyle
{
font: 14pt 宋体;
background-color:red;
color:white;
}
.tablestyle
{
z-index: 101;
left: 312px;
position: absolute;
top: 120px;
font: 10.5pt 宋体;
background-color: green;
}
18..config
//Web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="书名" value="Visual C# 2005 编程与开发技巧大全" />
<add key="作者" value="罗斌 罗顺文等编著" />
<add key="单价" value="68" />
</appSettings>
</configuration>
//////
Label1.Text = ConfigurationManager.AppSettings["书名"];
Label2.Text = ConfigurationManager.AppSettings["作者"];
Label3.Text = ConfigurationManager.AppSettings["单价"];
19.ascx
PlaceHolder
if (ViewState["MyControl"] != null)
{
PlaceHolder1.Controls.Clear();
Control MyControl = Page.LoadControl("WebUserControl.ascx");
PlaceHolder1.Controls.Add(MyControl);
}
////////////
PlaceHolder1.Controls.Clear();
Control MyControl = Page.LoadControl("WebUserControl.ascx");
PlaceHolder1.Controls.Add(MyControl);
ViewState["MyControl"] = true;
//////////////////////////////////////////////////////////
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["MyControl"] != null)
{
DropDownList DropDown = new DropDownList();
PlaceHolder1.Controls.Add(DropDown);
DropDown.ID = "MyControlID";
}
}
protected void Button1_Click(object sender, EventArgs e)
{//增加下拉列表控件
DropDownList MyDropDown = new DropDownList();
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(MyDropDown);
MyDropDown.ID = "MyControlID";
MyDropDown.Width =280;
MyDropDown.Items.Add(new ListItem("周华键:花心", "0"));
MyDropDown.Items.Add(new ListItem("刘德化:爱你一万年", "1"));
MyDropDown.Items.Add(new ListItem("成龙:真心英雄", "2"));
MyDropDown.Items.Add(new ListItem("孙楠:不见不散", "3"));
MyDropDown.Items.Add(new ListItem("任贤齐:深深太平洋", "4"));
MyDropDown.Items.Add(new ListItem("黄品源:你怎么舍得我难过", "5"));
ViewState["MyControl"] = true;
}
protected void Button2_Click(object sender, EventArgs e)
{//删除下拉列表控件
PlaceHolder1.Controls.Clear();
}
20.placehoder
protected void Page_Load(object sender, EventArgs e)
{// 显示控件值
if (this.TextBox1.Text.Length > 0)
{
for (int i = 1; i < Convert.ToInt16(this.TextBox1.Text) + 1; i++)
{
if (Request.Form.Get("CheckBox" + i.ToString()) == "on")
Response.Write("CheckBox" + i.ToString() + " 被选择!" + "<BR>");
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{//生成CheckBox控件
int MyCount = Convert.ToInt16(this.TextBox1.Text);
CheckBox MyCheckBox;
Literal BR;
HtmlInputHidden MyInput;
for (int i = 1; i < MyCount + 1; i++)
{
//产生控件
MyCheckBox = new CheckBox();
//指定控件名称ID
MyCheckBox.ID = "CheckBox" + i.ToString();
//设置控件标题文字
MyCheckBox.Text = "这是" + "CheckBox" + i.ToString() + "控件";
//将产生的CheckBox控件加入PlaceHolder
this.PlaceHolder1.Controls.Add(MyCheckBox);
//加入一个<BR>
BR = new Literal();
BR.Text = "<br>";
this.PlaceHolder1.Controls.Add(BR);
}
//产生一个Submit按钮
this.PlaceHolder1.Controls.Add(new HtmlInputButton("submit"));
//产生一个隐藏栏位,储存CheckBox个数
MyInput = new HtmlInputHidden();
MyInput.Value = MyCount.ToString();
MyInput.ID = "MyCountCheckBox";
this.PlaceHolder1.Controls.Add(MyInput);
}
21.
javascript
Response.Write( "<script language='javascript'>alert('消息提示框一');</script>") ;
this.Page.RegisterStartupScript("msgOnlyAlert","<script>alert('消息提示框二');</script>");
///////////////
//Page_Load
string MyInfo;
StringBuilder MyJava;
MyJava=new StringBuilder();
MyJava.Append ("<script language=JavaScript> ");
MyJava.Append ("function DeleteEmployeeConfirm() {");
MyJava.Append ("return confirm('确认删除操作吗?');}");
MyJava.Append ("</script>");
MyInfo=MyJava.ToString();
if(!IsClientScriptBlockRegistered("DeleteEmployeeConfirm") )
RegisterClientScriptBlock("DeleteEmployeeConfirm", MyInfo);
Button1.Attributes.Add("onclick", "return DeleteEmployeeConfirm()");
//Button1_Click
Response.Write("确认消息框返回结果:确认删除操作!");
22.
Response.Write(System.String.Format("<font size={0} >Visual C# 2005 编程技巧大全<br></font>",i));
23.
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
string MyDates="您选择了下列日期:"+"<br>";
for(int i=0;i<Calendar1.SelectedDates.Count;i++)
{
MyDates += Calendar1.SelectedDates[i].ToShortDateString() + "<br>";
}
Response.Write(MyDates);
}
Calendar
OnSelectionChanged="Calendar1_SelectionChanged" SelectionMode="DayWeekMonth"
24.回车键之后在多个textBox控件间跳转
<script language="javascript">
function keyDown()
{
var MyKeycode=event.keyCode;
if(MyKeycode==13)
event.keyCode=9;
};
document.onkeydown=keyDown;
</script>
25.邮箱验证
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
26.
<form id="form1" runat="server">
简体中文Office 2000 罗斯文数据库订单表记录表,当前页数:<%=GridView1.PageIndex + 1%>,总页数:<%=GridView1.PageCount%>
27.登陆
<system.web>
<authentication mode="Forms">
<forms name="MyDemo" loginUrl="Default2.aspx" protection="All" timeout="60" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
28.
产生1到10的不同随机数
bool IsExist(int[] Ar,int elem,int k)
{
for (int i=0;i<k ;i++ )
{
if(Ar[i]==elem)
{ return false; }
}
return true;
}
int[] Ar;
Random rd = new Random();
int number = 0;
Ar = new int[N];
int r;
while (number < N)
{
r = rd.Next(1, 11);
while(IsExist(Ar,r,number)==false)
{
r = rd.Next(1, 11);
}
Ar[number] = r;
number++;
}
for (int j = 0; j < N; j++)
Response.Write("<br>" + Ar[j].ToString());