1、提交信息的时候按钮变为不可用并显示"提交中..."
2、弹出有确认与取消的对话框
3、返回上一页(比如论坛发贴子,需要留言,如果没有注册的话先注册,注册完成后完回要回贴的那页,很方便)
4、ASP.NET按钮添加回车功能
把以下代码放在<head></head>之间即可
5、TextBox显示关键字,鼠标放上去消失
6、网友发表留言时Ctrl+回车的快捷键
<body onkeydown="if(event.ctrlKey && event.keyCode=='13') form1.Button1.click();">
7、GridView加一序号列
8、TextBox在页面加载时有选中
或者
9、解决Session失效
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="120"/>
10、中文乱码
<globalization requestEncoding="GB2312" responseEncoding="GB2312"/>
11、TextBox的一个事件
删除文件夹下的文件
DirectoryInfo d = Directory.CreateDirectory(@"D:\aaa");
FileInfo[] f = d.GetFiles("*.*");
foreach (FileInfo ff in f)
{
ff.Delete();
}
用JS根据RadioButtonList的选项控制CheckBoxList的操作
冒泡
protected void Page_Load(object sender, EventArgs e)
{
this.btnAddUser.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(btnAddUser, "Click") + ";this.disabled=true; this.value='提交中';");
}
{
this.btnAddUser.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(btnAddUser, "Click") + ";this.disabled=true; this.value='提交中';");
}
2、弹出有确认与取消的对话框
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return confirm('您确定要退出注册吗?');");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("aaaaa");
}
{
Button1.Attributes.Add("onclick", "return confirm('您确定要退出注册吗?');");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("aaaaa");
}
3、返回上一页(比如论坛发贴子,需要留言,如果没有注册的话先注册,注册完成后完回要回贴的那页,很方便)
protected void Page_Load(object sender, EventArgs e)
{
if (Request.UrlReferrer != null)
{
if (!IsPostBack)
{
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
url = (string)ViewState["UrlReferrer"];
}
}
//在确定按钮下写如下代码:
if (url != null)
{
Response.Redirect(url,false);
}
else
{
Response.Redirect("index.aspx",false);
}
{
if (Request.UrlReferrer != null)
{
if (!IsPostBack)
{
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
url = (string)ViewState["UrlReferrer"];
}
}
//在确定按钮下写如下代码:
if (url != null)
{
Response.Redirect(url,false);
}
else
{
Response.Redirect("index.aspx",false);
}
4、ASP.NET按钮添加回车功能
把以下代码放在<head></head>之间即可
<script language="javascript" type="text/javascript">
function document.onkeydown() //网页内按下回车触发
{
if(event.keyCode==13)
{
document.getElementById("Button1").click();
return false;
}
}
</script>
function document.onkeydown() //网页内按下回车触发
{
if(event.keyCode==13)
{
document.getElementById("Button1").click();
return false;
}
}
</script>
5、TextBox显示关键字,鼠标放上去消失
<asp:TextBox ID="txtepname" runat="server" onfocus="this.value=''" Width="255px">例如:某某商家</asp:TextBox>
6、网友发表留言时Ctrl+回车的快捷键
<body onkeydown="if(event.ctrlKey && event.keyCode=='13') form1.Button1.click();">
7、GridView加一序号列
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
8、TextBox在页面加载时有选中
<asp:TextBox ID="TextBox1" onfocus='this.select();' runat="server" Text=aaaaa></asp:TextBox>
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onfocus", "javascript:this.select()");
}
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onfocus", "javascript:this.select()");
}
或者
<body onload="document.getElementById('TextBox1').focus()" >
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" onfocus='this.select();' runat="server" Text=aaaaa></asp:TextBox></div>
</form>
</body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" onfocus='this.select();' runat="server" Text=aaaaa></asp:TextBox></div>
</form>
</body>
9、解决Session失效
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="120"/>
10、中文乱码
<globalization requestEncoding="GB2312" responseEncoding="GB2312"/>
11、TextBox的一个事件
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function a()
{
document.getElementById("TextBox2").value=document.getElementById("TextBox1").value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onkeyup="a();"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function a()
{
document.getElementById("TextBox2").value=document.getElementById("TextBox1").value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onkeyup="a();"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
删除文件夹下的文件
DirectoryInfo d = Directory.CreateDirectory(@"D:\aaa");
FileInfo[] f = d.GetFiles("*.*");
foreach (FileInfo ff in f)
{
ff.Delete();
}
用JS根据RadioButtonList的选项控制CheckBoxList的操作
<script type="text/javascript">
function OnRadioButtonListSelectChange(evt)
{
var input; //点击的RadioButtonList的RadioButton项
if(window.event != null) //IE 浏览器
input = event.srcElement;
else
input = evt.target; //FireFox 浏览器
if(input.value == 1)
SetCheckBoxListState(true);
else
SetCheckBoxListState(false);
}
function SetCheckBoxListState(enabled)
{
var oCBList = document.getElementById("<%=CheckBoxList1.ClientID %>");
var inputs = oCBList.getElementsByTagName("input");
for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type == "checkbox")
{
inputs[i].checked = false;
inputs[i].disabled = enabled;
}
}
}
</script>
function OnRadioButtonListSelectChange(evt)
{
var input; //点击的RadioButtonList的RadioButton项
if(window.event != null) //IE 浏览器
input = event.srcElement;
else
input = evt.target; //FireFox 浏览器
if(input.value == 1)
SetCheckBoxListState(true);
else
SetCheckBoxListState(false);
}
function SetCheckBoxListState(enabled)
{
var oCBList = document.getElementById("<%=CheckBoxList1.ClientID %>");
var inputs = oCBList.getElementsByTagName("input");
for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type == "checkbox")
{
inputs[i].checked = false;
inputs[i].disabled = enabled;
}
}
}
</script>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" onclick="OnRadioButtonListSelectChange(event)">
<asp:ListItem Value="0" Selected="true">参加</asp:ListItem>
<asp:ListItem Value="1">不参加</asp:ListItem>
</asp:RadioButtonList><br />
<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>项目1</asp:ListItem>
<asp:ListItem>项目2</asp:ListItem>
<asp:ListItem>项目3</asp:ListItem>
</asp:CheckBoxList>
<asp:ListItem Value="0" Selected="true">参加</asp:ListItem>
<asp:ListItem Value="1">不参加</asp:ListItem>
</asp:RadioButtonList><br />
<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>项目1</asp:ListItem>
<asp:ListItem>项目2</asp:ListItem>
<asp:ListItem>项目3</asp:ListItem>
</asp:CheckBoxList>
冒泡
int[] array=new int[10]{1,10,7,8,6,2,12,12,26,3};
for(int i=0;i<array.Length-1;i++)
{
for(int j=i+1;j<array.Length;j++)
{
if(array[j]<array[i])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
for(int i=0;i<array.Length;i++)
{
Response.Write(array[i]);
}