我修改/收藏的CSDN知識.(asp.net JavaScript)

來源:互聯網
上載者:User

1.如何把一個javascript 中的數組 從用戶端傳到伺服器端! 2005-09-13
向skytear() 又學一招,嘿嘿.  
<form id="Form1" method="post" runat="server">
    <INPUT id="hidden1" type="hidden" runat="server">
    <asp:Button id="Button7" runat="server" Text="獲得用戶端的數組"></asp:Button></P>
 </form>
    <script>
  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("<br>數組"+strValue); //不使用數組直接輸出.
   string []  result = hidden1.Value.Split(',');//形成數組
   foreach(string str in result)
   {
    Response.Write("<br><br>數組:"+str);
   }

  }
2.求Regex(漢字,字母,數字 混合驗證) 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
<asp:datagrid id="DataGrid1" runat="server" Width="100%"></asp:datagrid>
  /// <summary>
  /// 根據條件綁定DataGrid
  /// </summary>
  /// <param name="strSql"></param>
  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] = "<INPUT type=\"checkbox\" name=\"mobilelist\" value="+dr1["txtemmobile"].ToString()+">";
    dd[1] = "<a href=\"employeemodify.aspx?employee_id="+dr1["intemid"]+"\">"+dr1["txtemname"].ToString()+"</a>" ;
    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節),配置如下:<trace enabled = "true"/>
接著可以訪問你要測試的頁面,訪問之後在開啟IE輸入http://yourhost/yourApplication/trace.axd就可以看到剛才訪問頁面時伺服器處理請求的詳細資料,這個是比較準確的測試方法。
(2)
DateTime startTime;
void  Page_Init  (Object  sender,  EventArgs  e) 

startTime  =  DateTime.Now;
//Response.Write(startTime+"<br/>");
//Response.Write("page  init<br/>"); 

 
protected  override  void  Render(HtmlTextWriter  writer) 

base.Render(writer);
DateTime  endTime  =  DateTime.Now;
//Response.Write(endTime+"<br/>");
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.檔案下載
/// <summary>
/// 檔案下載
/// </summary>
/// <param name="FullFileName"></param>
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.固定狀態列,開啟的視窗在同一個視窗中
<head>
<base onmouseover="window.status='★-- >>═→ D113音樂網 WWW.D113.COM 祝各位網友〖天天快樂〗!~ ⊙_⌒γ  --★';return true">
<base target="play">
</head>

8http://crtvu.edu.cn/readddsx.html?id=1946 這種readddsx.html?id=1946是怎麼做的? 2005-09-17

開啟IIS,在你要設定的網站的屬性頁面的虛擬目錄標籤上,點擊“應用程式設定(Application Settings)”下的“配置(Configuration..)”按鈕,在開啟的“應用程式配置(Application Configuration)”視窗中的“應用程式對應(App Mappings)”標籤頁中,點擊下面的“添加(Add..)”按鈕,在彈出的“添加/編輯應用程式尾碼映射(Add/Edit Application Extension Mapping)”視窗中,在“可執行程式(Executable)”右邊的文字框框中輸入 C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll (檔案路徑會因.net架構版本的不同而不同,為安全起見,你可以在“應用程式對應(App Mappings)”標籤頁下的映射列表中雙擊“.aspx”,在彈出的視窗中選中它的“可執行程式(Executable)”文字框中的文本然後複製出來),在“尾碼名(Extension)”文字框中輸入你要添加的尾碼名“.html”,然後點擊確定儲存所有開啟的屬性視窗即完成IIS中的設定;
第二步:開啟你要配置的網站或虛擬目錄的根目錄下的web.config檔案,在<system.web>配置節下加入如下配置節:
<add verb="*" path="*.html" type="System.Web.UI.PageHandlerFactory"/>
儲存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 祕密金鑰加密
  /// <summary>
  /// 得到加密字串
  /// </summary>
  /// <param name="strText">要加密字串</param>
  /// <param name="strEncrKey">密鑰</param>
  /// <returns>加密後字串</returns>
   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";
    }
   }
  /// <summary>
  /// 得到解密後字串
  /// </summary>
  /// <param name="strText">解密字串</param>
  /// <param name="sDecrKey">密鑰</param>
  /// <returns>解密後字串</returns>
   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
把這個寫的類裡調用就 行了

禁止鍵盤輸入內容,禁止拷貝內容到某一輸入欄位(如使用者註冊中的確認輸入可以禁止拷貝前一個.).後一個是關閉IME的 2005-10-23
http://community.csdn.net/Expert/topic/4186/4186163.xml?temp=.1564295

<INPUT onmousedown="return false" onkeydown="return false" onpaste="return false" type="file" size="50" name="File"  >
<INPUT ContentEditable="false" type="file" size="50" name="File"  >
<INPUT readonly type="input" size="50" name="File"  >

<INPUT style="ime-mode:disabled" type="file" size="50" name="File"  > 關閉中文IME

只能輸入中文資訊
<asp:RegularExpressionValidator id="RegularExpressionValidator3" runat="server" ErrorMessage="RegularExpressionValidator"
      ControlToValidate="TextBox5" ValidationExpression="[\u4e00-\u9fa5]+">

ArrayList轉換為字元數組的方法    2005-11-01
   ArrayList array = new ArrayList();
   for (int i=0;i<10;i++)
   {
    array.Add( "zhuzhu"+i.ToString());
   }
   //string [] strs = (string [])(array.ToArray(System.Type.GetType("System.String")));//方法1
   string [] strs = new string[array.Count];  //方法二
   array.CopyTo(strs);
   foreach( string str in strs)
   {
    Response.Write("<br>"+str);
   }

    簡單隨即數
    Random rd = new Random();
    int nTempId = rd.Next(10000);
    
    日期格式
time1.ToString("yyyy-MM-dd HH:mm:ss");
time1.ToString("yyyyMMddHHmmss");

匯出到Excel的亂碼問題的解決   2006-03-08

  protected override void Render(HtmlTextWriter output)
  {
   Response.Clear();
   Response.Buffer= true;
   //Response.Charset="gb2312";   
   Response.AppendHeader("Content-Disposition","attachment;filename=employee.xls");
   //rResponse.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");//設定輸出資料流為簡體中文
   Response.ContentType = "application/ms-excel";//設定輸出檔案類型為excel檔案。 
   //下面是關鍵設定了它就不會亂碼了.也不知道為什麼
   Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
   DataTable dt = new DataTable();
   dt.Columns.Add(new DataColumn("員工姓名", typeof(string)));
   dt.Columns.Add(new DataColumn("登陸帳號", typeof(string)));
   dt.Columns.Add(new DataColumn("密碼", typeof(string)));
   string sql0="select * from table1 where id=10000";
   db.Sql=sql0;
   SqlCommand cmd1 = new SqlCommand(sql0,db.conn);
   cmd1.Connection.Open();
   SqlDataReader dr2 = cmd1.ExecuteReader();    
   while(dr2.Read())
   {
    DataRow dr3;
    dr3 = dt.NewRow();
    dr3[0] = dr2["name"];
    dr3[1] = dr2["LoginName"];
    dr3[2] = dr2["Passowrd"];
    dt.Rows.Add(dr3);
   }
   cmd1.Connection.Close();  
   DataView dv = new DataView(dt);   
   DataGrid1.DataSource =dv;
   DataGrid1.DataBind(); 
   DataGrid1.RenderControl(output);
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.