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

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
美团技术团队
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
月光博客
月光博客
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
I
Intezer
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
罗磊的独立博客
V
V2EX
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
A
About on SuperTechFans
Scott Helme
Scott Helme
Vercel News
Vercel News
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
Hacker News: Ask HN
Hacker News: Ask HN
C
CERT Recently Published Vulnerability Notes
G
Google Developers Blog
B
Blog
博客园 - 叶小钗
WordPress大学
WordPress大学
博客园 - 聂微东
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
IT之家
IT之家
C
Cybersecurity and Infrastructure Security Agency CISA
P
Palo Alto Networks Blog
小众软件
小众软件
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog

博客园 - 嚣张的沉默

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

            }