vs2005开发的一些总结

    技术2022-05-11  80

    =============================================================== vs2005的数据绑定控件在编辑和删除时会自动把datakeynames添加进去 =========================== Page.MaintainScrollPositionOnPostBack = true;//如果页面太长则让他自动保存上次的位置 //Page.SmartNavigation = true;//此法已经不推荐使用 =========================== 用Request.Form["tprovince"]获取,因为你是客户端改变的,没有保存到viewstate 用这个Request.Form[this.tprovince.UniqueID] Request.Form["控件ID"] 获取客户端改变的select值 ============================ .net中引用外部js文件后出错,不能dopostback了,编码都是utf-8, 只要在引用js的语句下面再加一行javascript就行了。why  <script language="javascript" type="text/javascript" src="../OCRS_NET.js" />     <script language="javascript" type="text/javascript">     function doNothing()     {         //     }     </script> ================================= 前台代码 <%#DataBinder.Eval(Container.DataItem,"NewsTitle") %> 修改为 <%# myfunc(DataBinder.Eval(Container.DataItem,"NewsTitle")) %> ===或者在设计器里:funcEvalSta(Eval("sStatus")) 后台代码 public string myfunc(object s)   {    return s.ToString().SubString(0,11);   } ================================= css中超链接的样式顺序不可搞错,先link再visited再hover再active 这样效果最好 如: a.news:link {  font-family: "宋体";  font-size: 12px;  color: #666666;  text-decoration: none; } a.news:visited {  font-family: "宋体";  font-size: 12px;  color: #666666;  text-decoration: none; } a.news:hover {  font-family: "宋体";  font-size: 12px;  color: #000000;  text-decoration: underline; } a.news:active {  font-family: "宋体";  font-size: 12px;  color: #000000;  text-decoration: underline; } ================================== textbox设置为password时动态添加文字不会添加的解决方法: txtPassword.Attributes.Add("value",curUser.sPassWord.Trim()); ================================== //出错默认转到出错页面     void Application_Error(object sender, EventArgs e)     {         // 在出现未处理的错误时运行的代码         Exception errorInfo = Server.GetLastError().InnerException;         string strMessage = "错误信息:" + Server.UrlEncode(errorInfo.Message);         string strPageUrl = Request.Path;         strMessage += "出错页面路径:" + strPageUrl;         Server.ClearError();         Response.Redirect("~//Error.aspx?ErrInfo=" + strMessage, true);

        }===================================select isnull(@s1,'uffjf') sql语句中判断为空则值默认为后面的参数判断是否为null是 if (@param is null)不是if (@param = null)===================================在formview里面做dropdownlist的数据联动时会出错,可以不绑定,而在代码中(inserting或updateing时)添加params的defaultvalue就可以解决===================================新打开一页asp.net控件:ImageButton1.Attributes.Add("onclick", "javascript:window.open('XXX.aspx','_blank');return false");===================================客户端可以myinput.focus()获得焦点//以前竟然不知道 晕===================================如果不想某个按钮执行验证控件的检测,则可以把他的(按钮的)CausesValidation设置为false===================================sql datasource中updated后e.affectrows可以取得影响的行数,或者mp返回值===================================网易邮箱登录input的颜色样式txtUsername.Attributes.Add("onMouseOver", "this.style.borderColor='#9ecc00'");txtUsername.Attributes.Add("onMouseOut", "this.style.borderColor='#84a1bd'");===================================insertting时检测重复,e.cancel = true;然后return就可以保存状态===================================IIS中如果想有某文件夹的写权限可以设置network service用户权限。====================================sqlDataSource把CancelSelectOnNullParameter设为false则可以传入空的参数。====================================客户端获取asp.net的lable控件的值不要document.getElementbyID('').value;而是应该document.getElementbyID('').innerText; or innerHTML====================================asp.net的控件比如textbox设置为readonly=true则用javascript添加他的value值,然后后台就取不到====================================在</head>之前增加<base target="_self" />,则var a=window.showModalDialog("GetInv3.aspx",'a',"dialogWidth=1000px;dialogHeight=740px");出来的窗体在自己内部跳转超链接。====================================根据数据改变Gridview的颜色:        for (int i = 0; i < gvInvAlert.Rows.Count; i++)        {            if (gvInvAlert.Rows[i].Cells[7].Text == "报警")            {                gvInvAlert.Rows[i].ForeColor = System.Drawing.Color.Red;            }        }但是此方法只对非模板列起作用,如果不想在edit时显示某列,可以设置其applyformatinEditmod为false====================================Request.ServerVariables["HTTP_USER_AGENT"];//获取浏览器信息Request.ServerVariables["REMOTE_ADDR"];//获取ip地址====================================<input οnfοcus="if( this.value=='用 Google 搜索本站') {this.value='' };" id="gq" value="用 Google 搜索本站" type="text">====================================if string.IsNullOrEmpty()====================================    protected void gvStoreInit_RowDataBound(object sender, GridViewRowEventArgs e)    {        //鼠标经过griadview时改变样式        string sCSSover = "mosovTR";        string sCSSout = "mosoutTR";        if (e.Row.RowType == DataControlRowType.DataRow)        {            e.Row.Attributes.Add("onmouseover", "this.className = '" + sCSSover + "'");            e.Row.Attributes.Add("onmouseout", "this.className = '" + sCSSout + "'");        }    }====================================    public class JavaScriptConstant    {        internal const string jsClickAndDoubleClick = @"<script type=""text/javascript"">        //<![CDATA[        var isDoubleClick = false;        function yy_RowClick(id)        {            setTimeout(""yy_RowClickTimeout('""+id+""')"", 300);        }        function yy_RowClickTimeout(id)        {            if (isDoubleClick == false)            {                // 执行ID所指按钮的click事件                document.getElementById(id).click();            }            isDoubleClick = true;        }        function yy_RowDoubleClick(id)        {            if (isDoubleClick == true)            {                // 执行ID所指按钮的click事件                document.getElementById(id).click();            }            isDoubleClick = true;        }        //]]>        </script>";    }======================================= 


    最新回复(0)