惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
V
V2EX
WordPress大学
WordPress大学
博客园 - Franky
Last Week in AI
Last Week in AI
博客园 - 司徒正美
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
腾讯CDC
The Hacker News
The Hacker News
Hugging Face - Blog
Hugging Face - Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
A
Arctic Wolf
量子位
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
News and Events Feed by Topic
雷峰网
雷峰网
博客园_首页
Google Online Security Blog
Google Online Security Blog
Spread Privacy
Spread Privacy
罗磊的独立博客
H
Hacker News: Front Page
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
IT之家
IT之家
The Cloudflare Blog
爱范儿
爱范儿
博客园 - 叶小钗
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 嚣张的沉默

读写txt文档 限制TextBox输入字数 计算TextBox输入的字数 我常用的正则与SQL语句 DataSet导入到Excel 年月日联动的JS代码 用户控件的传值方法 Repeater模板列 百叶窗效果 建站安全 倒计时代码 解决SQL2000安装服务器挂起 删除.NET的最近项目 屏幕右下角弹出广告 DataSet写入、导出XML 上传图片重命名并创建文件夹 自动跳转页面带参数 微软出的AJAX控件的安装(转载) 第一次开博
asp.net的几个小技巧
嚣张的沉默 · 2008-01-22 · via 博客园 - 嚣张的沉默

1、提交信息的时候按钮变为不可用并显示"提交中..."

protected void Page_Load(object sender, EventArgs e)
    
{
        
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");
    }


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);
                }

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>

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>

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()"); 

    }

或者

<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>

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>

删除文件夹下的文件
 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>

<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>

冒泡

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]);

            }