asp.net 小技巧

本文介绍了ASP.NET开发中的一些实用技巧,包括防止GridView中的数据列换行、使FileUpload控件变为只读状态、利用不同加密算法提高Cookie的安全性、实现虚线效果以及通过JavaScript预览上传图片等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GridView中数据列的内容太长的时候经常会出现换行
转换成模板列,在内容两边加上 <nowrap> </nowrap>

让   FileUpload   文本框只读
C# code
<asp:FileUpload runat="server" style="height:20px;" unselectable="on" ID="fileUpdate" />

Cookie中的数据以文本的形式存在客户端计算机,考虑它的安全性,最好在将数据存入Cookie之前对其进行加密。
加密的方法很多,比较简单一点的有:Base64,md5,sha等,而相对比较复杂一点的有:DES,TripleDES,RC2,Rijndael等。
下面是的代码实现了将数据存入Cookie之前采用散列的算法进行加密.
Private   void   Login_Click(object   sender,System   EventArgs   e)
{
string   Name   =   NameBox.Text;
string   Pass   =   PassBox.Text;
Response.Cookies[ "name "].Value   =   FormsAuthentication.HashPasswordForStoringInConfigFile(Name,   "md5 ");
                Response.Cookies[ "pass "].Value   =   FormsAuthentication.HashPasswordForStoringInConfigFile(Pass,   "md5 ");
}
加密的方法很多,使用比较复杂的加密算法,安全性比较高些,但占用服务器资源比较大,会减慢整个网站的访问速度。
所以对Cookie加密在考虑三个方面:1:安全性,2:Cookie容量,3:整个网站的性能。









ENTER键可以让光标移到下一个输入框
<input   onkeydown= "if(event.keyCode==13)event.keyCode=9 ">



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="26_虚线效果.aspx.cs" Inherits="_26_虚线效果" %> <!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 runat="server"> <title>无标题页</title> <%-- 方法二--%> <STYLE type=text/css> .dotline { BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: dotted; BORDER-RIGHT-STYLE: dotted; BORDER-TOP-STYLE: dotted } </STYLE> </head> <body> <form id="form1" runat="server"> <div> <hr style="BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: dotted; BORDER-RIGHT-STYLE: dotted; BORDER-TOP-STYLE: dotted" color=#000000 size=1 /> 方法2: <hr class=dotline color=green size=1 /> </div> </form> </body> </html>

<input   type= "file "   onchange= "javascript:document.getElementById( 'image ').src=this.value "/>
<input   type= "image "   src= " "   id= "image "/>
这样在选中要上传的图片时,就可以看见自己要上传的了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值