zoukankan      html  css  js  c++  java
  • 我修改/收藏的CSDN知识.(asp.net JavaScript)

    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.求正则表达式(汉字,字母,数字 混合验证) 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
    把这个写的类里调用就 行了


    禁止键盘输入内容,禁止拷贝内容到某一输入域(如用户注册中的确认输入可以禁止拷贝前一个.).后一个是关闭输入法的 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"  > 关闭中文输入法

    只能输入中文信息
    <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);
      }

  • 相关阅读:
    MySQL概述
    Seleniumselenium基础入门
    MySQL数据库的安装与使用
    元素定位_id
    Selenium浏览器的前进、后退、刷新
    元素定位_tag_name
    Selenium浏览器操作_窗口大小设置
    元素定位_name
    搭建maven服务器(repository)
    使用dos命令生成目录树
  • 原文地址:https://www.cnblogs.com/draeag/p/710881.html
Copyright © 2011-2022 走看看