1.如何把一个javascript 中的数组 从客户端传到服务器端! 2005-09-13
向skytear() 又学一招,嘿嘿.
<script type="text/javascript">
var array1 = new Array();
array1[0] ="你";
array1[1] = "我";
array1[2] ="他";
document.all.hidden1.value = array1;
</script>
--------------------------------------------------
private void Button7_Click(object sender, System.EventArgs e)
{
string strValue = this.hidden1.Value;
Response.Write("
数组"+strValue); //不使用数组直接输出.
string [] result = hidden1.Value.Split(',');//形成数组
foreach(string str in result)
{
Response.Write("
数组:"+str);
}
}
2.求正则表达式(汉字,字母,数字 混合验证) 2005-09-13
首位汉字,
2-4位为字母,
第5位汉字,
6-14位为数字,
最后一位为汉字
^[/u4e00-/u9fa5][a-zA-Z]{3}[/u4e00-/u9fa5]/d{9}[/u4e00-/u9fa5]$
3.如何动态在datagrid中加入列标题和列内容? 2005-09-13
使用动态生成DataTable后,把DataTable绑定到DataGrid
///
/// 根据条件绑定DataGrid
///
///
private void DataBind(string strSql)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("字段0标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段1标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段2标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段3标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段4标题", typeof(string)));
SqlCommand cmd2 = new SqlCommand(strSql,db.conn);
cmd2.Connection.Open();
SqlDataReader dr1 = cmd2.ExecuteReader();
while(dr1.Read())
{
DataRow dd;
dd = dt.NewRow();
dd[0] = "";
dd[1] = ""+dr1["txtemname"].ToString()+"" ;
dd[2] = dr1["em_position"];
dd[3] = dr1["txtemmobile"];
dt.Rows.Add(dd);
}
cmd2.Connection.Close();
DataView dv = new DataView(dt);
DataGrid1.DataSource =dv;
DataGrid1.DataBind();
}
4.怎样测试一个页面的运行时间
(1)首先在web.config里面配置trace节(该节属于system.web节),配置如下:
接着可以访问你要测试的页面,访问之后在打开IE输入http://yourhost/yourApplication/trace.axd就可以看到刚才访问页面时服务器处理请求的详细信息,这个是比较准确的测试方法。
(2)
DateTime startTime;
void Page_Init (Object sender, EventArgs e)
{
startTime = DateTime.Now;
//Response.Write(startTime+"
");
//Response.Write("page init
");
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
DateTime endTime = DateTime.Now;
//Response.Write(endTime+"
");
TimeSpan ts = endTime - startTime;
Response.Write("done in " + ts.Milliseconds.ToString());//ts.TotalMilliseconds.ToString());
}
5.c#中的日期差额:DateDiff在VB中有.
using System.TimeSpan:
DateTime dt = ...
DateTime d2 = ...
TimeSpan ts = dt - dt2;
n = ts.Hours;
6.文件下载
///
/// 文件下载
///
///
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
7.固定状态栏,打开的窗口在同一个窗口中
保存web.config文件,然后将所有的aspx文件的后缀改为html,在浏览器中打开看看是不是和aspx文件一样的效果!
http://www.ssite.cn/forums/104/ShowPost.aspx
adandelion
study English http://forums.devshed.com/ adandelion
我有一个datagrid绑定了记录,
在每条记录的右边有一个imagebutton
当用户点击imagebutton时,就执行一个程序。
但此时如果我用F5刷新页面时,为什么又执行了一次imagebutton事件呀
你要设置页面的 smartnavigation=true 才不会让地址栏累计历史纪录
UTF-8转换成中文 2005-09-24
http://xmaspx.com/blogs/hackate/
private void Button2_Click(object sender, System.EventArgs e)
{
string utfinfo = "欢迎使用";
string gb2312info = string.Empty;
Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding("gb2312");
// Convert the string into a byte[].
byte[] unicodeBytes = utf8.GetBytes(utfinfo);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(utf8, gb2312, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
gb2312info = new string(asciiChars);
Response.Write(gb2312info);//欢迎使用
}
#########怎样将字符串转换成可以执行的代码??? 2005-10-03
http://community.csdn.net/Expert/topic/3985/3985223.xml?temp=.2579767
下面的把字符串中的数字表达式求值:
double a = (double)Eval("1+1*2");
string s = a.ToString();
public static object Eval(string expression)
{
System.Data.DataTable table=new System.Data.DataTable();
System.Data.DataColumn Col=new System.Data.DataColumn("AAA",typeof(string),expression);
table.Columns.Add(Col);
table.Rows.Add(new object[] {""});
return table.Rows[0][0];
}
----------------------
Microsoft.JScript.Vsa.VsaEngine ve=Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
object qswhEval3(string Expression){
return Microsoft.JScript.Eval.JScriptEvaluate(Expression,ve);
}
只需要添加Microsoft.JScript和Microsoft.Vsa两个引用就OK,超简洁....呵呵,多谢楼上朋友们的帮助.......
按照时间命名
string fileName = System.DateTime.Now.ToString("yyyyMdHms");
DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond.ToString()
+IP地址.
密钥加密
#region 密钥加密
///
/// 得到加密字符串
///
/// 要加密字符串
/// 密钥
/// 加密后字符串
public string DesEncrypt(string strText, string strEncrKey)//加密函数
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,strEncrKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception error)
{
return "error:" +error.Message+"/r";
}
}
///
/// 得到解密后字符串
///
/// 解密字符串
/// 密钥
/// 解密后字符串
public string DesDecrypt(string strText,string sDecrKey)//解密函数
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch(System.Exception error)
{
return "error:"+error.Message+"/r";
}
}
#endregion
把这个写的类里调用就 行了
禁止键盘输入内容,禁止拷贝内容到某一输入域(如用户注册中的确认输入可以禁止拷贝前一个.).后一个是关闭输入法的 2005-10-23
http://community.csdn.net/Expert/topic/4186/4186163.xml?temp=.1564295
向skytear() 又学一招,嘿嘿.
<script type="text/javascript">
var array1 = new Array();
array1[0] ="你";
array1[1] = "我";
array1[2] ="他";
document.all.hidden1.value = array1;
</script>
--------------------------------------------------
private void Button7_Click(object sender, System.EventArgs e)
{
string strValue = this.hidden1.Value;
Response.Write("
数组"+strValue); //不使用数组直接输出.
string [] result = hidden1.Value.Split(',');//形成数组
foreach(string str in result)
{
Response.Write("
数组:"+str);
}
}
2.求正则表达式(汉字,字母,数字 混合验证) 2005-09-13
首位汉字,
2-4位为字母,
第5位汉字,
6-14位为数字,
最后一位为汉字
^[/u4e00-/u9fa5][a-zA-Z]{3}[/u4e00-/u9fa5]/d{9}[/u4e00-/u9fa5]$
3.如何动态在datagrid中加入列标题和列内容? 2005-09-13
使用动态生成DataTable后,把DataTable绑定到DataGrid
///
/// 根据条件绑定DataGrid
///
///
private void DataBind(string strSql)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("字段0标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段1标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段2标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段3标题", typeof(string)));
dt.Columns.Add(new DataColumn("字段4标题", typeof(string)));
SqlCommand cmd2 = new SqlCommand(strSql,db.conn);
cmd2.Connection.Open();
SqlDataReader dr1 = cmd2.ExecuteReader();
while(dr1.Read())
{
DataRow dd;
dd = dt.NewRow();
dd[0] = "";
dd[1] = ""+dr1["txtemname"].ToString()+"" ;
dd[2] = dr1["em_position"];
dd[3] = dr1["txtemmobile"];
dt.Rows.Add(dd);
}
cmd2.Connection.Close();
DataView dv = new DataView(dt);
DataGrid1.DataSource =dv;
DataGrid1.DataBind();
}
4.怎样测试一个页面的运行时间
(1)首先在web.config里面配置trace节(该节属于system.web节),配置如下:
接着可以访问你要测试的页面,访问之后在打开IE输入http://yourhost/yourApplication/trace.axd就可以看到刚才访问页面时服务器处理请求的详细信息,这个是比较准确的测试方法。
(2)
DateTime startTime;
void Page_Init (Object sender, EventArgs e)
{
startTime = DateTime.Now;
//Response.Write(startTime+"
");
//Response.Write("page init
");
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
DateTime endTime = DateTime.Now;
//Response.Write(endTime+"
");
TimeSpan ts = endTime - startTime;
Response.Write("done in " + ts.Milliseconds.ToString());//ts.TotalMilliseconds.ToString());
}
5.c#中的日期差额:DateDiff在VB中有.
using System.TimeSpan:
DateTime dt = ...
DateTime d2 = ...
TimeSpan ts = dt - dt2;
n = ts.Hours;
6.文件下载
///
/// 文件下载
///
///
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
7.固定状态栏,打开的窗口在同一个窗口中
保存web.config文件,然后将所有的aspx文件的后缀改为html,在浏览器中打开看看是不是和aspx文件一样的效果!
http://www.ssite.cn/forums/104/ShowPost.aspx
adandelion
study English http://forums.devshed.com/ adandelion
我有一个datagrid绑定了记录,
在每条记录的右边有一个imagebutton
当用户点击imagebutton时,就执行一个程序。
但此时如果我用F5刷新页面时,为什么又执行了一次imagebutton事件呀
你要设置页面的 smartnavigation=true 才不会让地址栏累计历史纪录
UTF-8转换成中文 2005-09-24
http://xmaspx.com/blogs/hackate/
private void Button2_Click(object sender, System.EventArgs e)
{
string utfinfo = "欢迎使用";
string gb2312info = string.Empty;
Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding("gb2312");
// Convert the string into a byte[].
byte[] unicodeBytes = utf8.GetBytes(utfinfo);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(utf8, gb2312, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
gb2312info = new string(asciiChars);
Response.Write(gb2312info);//欢迎使用
}
#########怎样将字符串转换成可以执行的代码??? 2005-10-03
http://community.csdn.net/Expert/topic/3985/3985223.xml?temp=.2579767
下面的把字符串中的数字表达式求值:
double a = (double)Eval("1+1*2");
string s = a.ToString();
public static object Eval(string expression)
{
System.Data.DataTable table=new System.Data.DataTable();
System.Data.DataColumn Col=new System.Data.DataColumn("AAA",typeof(string),expression);
table.Columns.Add(Col);
table.Rows.Add(new object[] {""});
return table.Rows[0][0];
}
----------------------
Microsoft.JScript.Vsa.VsaEngine ve=Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
object qswhEval3(string Expression){
return Microsoft.JScript.Eval.JScriptEvaluate(Expression,ve);
}
只需要添加Microsoft.JScript和Microsoft.Vsa两个引用就OK,超简洁....呵呵,多谢楼上朋友们的帮助.......
按照时间命名
string fileName = System.DateTime.Now.ToString("yyyyMdHms");
DateTime.Now.ToString("yyyyMMddhhmmss") + DateTime.Now.Millisecond.ToString()
+IP地址.
密钥加密
#region 密钥加密
///
/// 得到加密字符串
///
/// 要加密字符串
/// 密钥
/// 加密后字符串
public string DesEncrypt(string strText, string strEncrKey)//加密函数
{
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,strEncrKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception error)
{
return "error:" +error.Message+"/r";
}
}
///
/// 得到解密后字符串
///
/// 解密字符串
/// 密钥
/// 解密后字符串
public string DesDecrypt(string strText,string sDecrKey)//解密函数
{
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch(System.Exception error)
{
return "error:"+error.Message+"/r";
}
}
#endregion
把这个写的类里调用就 行了
禁止键盘输入内容,禁止拷贝内容到某一输入域(如用户注册中的确认输入可以禁止拷贝前一个.).后一个是关闭输入法的 2005-10-23
http://community.csdn.net/Expert/topic/4186/4186163.xml?temp=.1564295