我自己记录的C#2.0笔记之三

1.如下代码,目的:先构造基础类,基础类完成默认的操作,实体类继承自基础类,主要是初始化数据。
using System;
     public struct sql
    {
        public string query;
    }
public class cTable
{
    public virtual sql getsql()
    {
        throw new Exception ("err ");
    }

    public virtual void m()
    {
        Console.WriteLine( getsql().query );
    }
}

public class cUser:cTable
{
    public override sql getsql()
    {
        sql s;
        s.query = "llll";
        return s;
    }
}

2.Request的Cookie是保存到客户机上的.Request的Cookie是随窗体变量集合保存到服务器上的.
3.解决asp.net中上传较大文件出现超时等错误
修改web.config文件
<system.web>
<httpRuntime executionTimeout="3600"  maxRequestLength="1048576"/>
</system.web>
4.页面的多线程.
5.Javascript封装 Combox 和日期控件件.
6.Odmc
7. GridView 复制样式:
            gv.HeaderStyle.CopyFrom(this.gvInfo.HeaderStyle);
            gv.RowStyle.CopyFrom(this.gvInfo.RowStyle);
            gv.AlternatingRowStyle.CopyFrom(this.gvInfo.AlternatingRowStyle);
            gv.EditRowStyle.CopyFrom(this.gvInfo.EditRowStyle);

            gv.PagerStyle.CopyFrom(this.gvInfo.PagerStyle);

            gv.BackColor = this.gvInfo.BackColor;
            gv.BorderColor = this.gvInfo.BorderColor;
            gv.BorderStyle = this.gvInfo.BorderStyle;
            gv.BorderWidth = this.gvInfo.BorderWidth;
            gv.GridLines = this.gvInfo.GridLines;
            gv.ForeColor = this.gvInfo.ForeColor;
            gv.CellPadding = this.gvInfo.CellPadding;
            gv.CellSpacing = this.gvInfo.CellSpacing;


1.用户控件里的hidden如果是 RunAt=Server 的话,那么它的 ID 和 Name 都会改变.
如果是运行在客户端的话,那么它的ID和Name都不会改变
2.如果是服务器端运行的控件的话,那么它会改变成准确的位置offsetLeft等.如果是客户端的话.要加上它父辈树的相对位置.
3.关于DataGrid.Controls的结构.
              Table dgt = this.DataGrid1.Controls[0]  as Table ;

            for ( int i=0;i<dgt.Rows.Count ;i++)
            {
                DataGridItem dgi = dgt.Rows[i] as DataGridItem  ;
                if( dgi.ItemType == ListItemType.Header )
                {
                    dgi.Cells[0].Controls.Add ( btnOK ) ;
                }
            }
    也就是说, DataGrid 只有一个Contorls ,是一个 总的 Table .可直接用 as 来转换.
    再往下是每个行的集合.可直接用 as 转换为 DataGridItem .
4.Response是从服务器流向客户端的数据流.
  Request 是从客户端流向服务器的数据流.
    如果读写Cookie的话.写客户端Cookie 是用Response.Cookie .读客户端Cookie是Request.Cookie.
4.1 JavaScript 如何得到 Request的值
    用 服务器端代码取 : <%= Request[""] %>
5.关于COM编译成.NET的DLL.
6.
<script language="javascript">
function document.onclick()
{
eval(event.srcElement.id+".innerHTML=event.srcElement.id")
}
</script>
<table border="1" width="412" height="239">
        <tr>
                <td height="108" width="202"  id="search1"> </td>
                <td height="108" width="194" id="search2"> </td>
        </tr>
        <tr>
                <td height="121" width="202" id="search3"> </td>
                <td height="121" width="194" id="search4"> </td>
        </tr>
</table>
7.如何防刷新.
8.如何验证表单不被修改.
9.ASP.NET内部实现机制.
10.正则表达式.
11.XML
12.

/// <summary>
        /// 返回去除中间多余字符后的字符串.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static decimal getDecimalFromString( string Value )
        {
            string retVal  = Regex.Replace(Value,@"[^\d.]","") ;

            string[]  sa = retVal.Split( '.' ) ;

            if ( sa.Length > 1 )
            {
                retVal = sa[0] + "."  + string.Join("", sa,1,sa.Length -1 ) ;
            }
 
            return CmnProc.getDecimal( retVal.Trim() );
        }
13.
        /// <summary>
        /// 页面回发保持之前位置.
        /// </summary>
        /// <param name="webPage"></param>
        public  static void SetFocus(Page webPage)
        {  
            string strTop = "_SCROLLTOP";
            string strLeft = "_SCROLLLEFT";
            string posTop = webPage.Request.Form[strTop];
            string posLeft = webPage.Request.Form[strLeft] ;
            if ( posTop == String.Empty || posTop == null ) posTop = "0";
            if ( posLeft == String.Empty  || posLeft == null ) posLeft = "0" ;

            webPage.RegisterHiddenField(strTop,posTop);
            webPage.RegisterHiddenField(strLeft,posLeft);

            string script = "<script for=document event=onclick>Form1.{0}.value=document.body.scrollTop;Form1.{1}.value = document.body.scrollLeft;</script>";
            script = string.Format( script ,strTop ,strLeft ) ;
            webPage.RegisterClientScriptBlock( "_doUnload", script );
            
            if( !webPage.IsPostBack ) return;

            string str = "<script>document.body.scrollTo({0},{1});</script>";
            str = string.Format( str ,posLeft, posTop ) ;
            webPage.RegisterStartupScript("_setScroll", str);
        }

14.
Response.Write("<script>alert('ok');window.navigate('" + Request.Url.ToString() + "');</script>");
15.
public static bool IsNull( int Value )
        {
            if ( ( (IntPtr)Value ).ToPointer() == null )
            {
                return true ;
            }
            else
            {
                return false;
            }
        }
15.
ASP.NET超时设置

1.IIS->[网站]->属性-》连接超时。默认为120秒
2.WEB.CONFIG 手工添加httpRuntime,如
<system.web>
 <httpRuntime maxRequestLength="1000000" executionTimeout="2000" />
</system.web>
3.同步执行WEBSERVICE时,需要设置TIMEOUT属性,如
 CompilerSvr.MyFavoritesService compiler=new FDN.DMS.Controls.CompilerSvr.MyFavoritesService();
   compiler.Timeout =2000000; //毫秒
4.根据 HTTP 状态码得到状态定义.
5.只有BoundColumn列和自动生成列,才可以通过TableCell.Text属性读取显示的文本。HyperLinkColumn、ButtonColumn、EditCommandColumn都需要将目标控件转换成相应的控件。
6.在 客户端链接 和服务器端链接是不同的.
    典型环境, 在 Equip 目录下一个页面  EquipList ,用到了一个在 Cus_Con 目录下的一个 EquipSynopsis.ascx 的用户控件.在该用户控件里有一个 <A> 链接.服务器端有公共属性
        public string HrefToInfo
        {
            get
            {
                return "equipInfo.aspx?id=" + EquipID.ToString()  ;
            }
        }

    如果这样写
    <A Href='<% HrefToInfo %>'>详细信息</A>  这样没问题.,也是很合道理的.

    如果这样写
    <A id="aBtnToInfo"></a>
    在服务器 Page_Load 里设置如下:
    this.aBtnToInfo.HREF = HrefToInfo ; 这样,客户端就会生成如下HTML <a id="rptList__ctl0__ctl0_aBtnToInfo" href="../Cus_Con/equipInfo.aspx?id=6">详细信息</A>
    如果在用户控件里控件是运行在服务器端的,那么它的ID会改变.同时,它的部分属性 比如 HREF ,会用户控件为当前目录.
    总之.如果用户控件里的是 服务器控件 ,那么它的 HREF 在服务器端要写成 以用户控件为当前路径的相对位置 为链接.
        如果用户控件是 客户端控件,那么它的 HREF 会以页面为当前路径的链接.

posted @ 2009-03-09 00:56  NewSea  阅读(230)  评论(0)    收藏  举报