Asp.net 随记 Part3 (53 70)

70.如何asp:TextBox或者Html Input 中的自动记忆功能

比如:在开发WebForm时经常会使用TextBox,TextBox有一个很好的功能,可以记忆前几次录入的一次值;再你下一次使用只要双击TextBox时,它就会自动把前几次输入的值的以下拉框的形式呈现,如下图

image

但是有一些情况,我们必须屏蔽此记忆功能。

比如:输入信用卡卡码时。

那如何屏蔽?

<asp:TextBox> 设置AutoCompleteType="Disabled"即可

Html Input 设置 autoComplete =”off”

69.System.Runtime.InteropServices.COMException

http://aspadvice.com/blogs/robertb/archive/2008/05/07/System.Runtime.InteropServices.COMException-in-WAP-VS-2008-Project.aspx

I had a Visual Studio 2008 Web Application Project working on one my machines, and when I tried to open it on another Vista machine I got a dialog with simply "System.Runtime.InteropServices.COMException" and the project would not load. 

I found the following known bug already posted about it (http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=317124), but I checked and the URL used for the project to open in IIS was correct.  While reading I noticed it also talked about the metabase.  I went and installed the metabase compatibility, and it solved my problem:

原因:

WebApplication 配置为使用IIS,而机器安装的是IIS7,并且IIS7没有安装IIS6元数据库与IIS6配置兼容性组件(IIS 6 metabase and IIS 6 Configuration Compatiblity ASP.NET)

解决:

用记事本打开项目文件 .csproj (C#),找到 <UseIIS>True</UseIIS> 节点,修改为 <UseIIS>False</UseIIS>,使用 VS 内置WebServer

因为未安装 Internet Information Server (IIS) 6 元数据库兼容性组件和 IIS 6 管理控制台组件,所以 Microsoft Exchange Server 2007 安装程序无法继续在基于 Windows Server 2008 或基于 Windows Vista 的目标计算机上安装客户端访问服务器角色、邮箱服务器角色或 Exchange 2007 管理工具。

Exchange 2007 安装程序要求基于 Windows Server 2008 或基于 Windows Vista 的计算机(要在该计算机上安装 Exchange 2007 客户端访问服务器角色、邮箱服务器角色或 Exchange 2007 管理工具)上安装有 IIS 6 元数据库兼容性组件和 IIS 6 管理控制台组件。

若要解决此问题,请将 IIS 6 元数据库兼容组件安装到目标计算机,然后重新运行 Microsoft Exchange 安装程序。

使用 Windows Server 2008 服务器管理器安装 IIS 6.0 管理兼容组件

  1. 依次单击“开始”、“管理工具”和“服务器管理器”

  2. 在左侧导航窗格中,展开“角色”,再右键单击“Web 服务器 (IIS)”并选择“添加角色服务”

  3. 在“选择角色服务”窗格上,向下滚动到“IIS 6 管理兼容性”

  4. 选中“IIS 6 元数据库兼容性”和“IIS 6 管理控制台”所对应的复选框。

  5. 单击“选择角色服务”窗格中的“下一步”,再单击“确认安装选择”窗格中的“安装”

  6. 单击“关闭”退出“添加角色服务”向导。

使用 Windows Vista 控制面板安装 IIS 6.0 管理兼容性组件

  1. 依次单击“开始”、“控制面板”、“程序和功能”和“打开或关闭 Windows 功能”。

  2. 打开“Internet Information Services”。

  3. 打开“Web 管理工具”。

  4. 打开“IIS 6.0 管理兼容性”。

  5. 选中“IIS 6 元数据库与 IIS 6 配置的兼容性”及“IIS 6 管理控制台”所对应的复选框。

  6. 单击“确定”

68.ASP.NET中url传递中文的解决方案
 http://www.diybl.com/course/4_webprogram/asp.net/asp_netshl/2008510/115352.html

67.JavaScript 使用Array对象进行集中检查页面中的必须录入项,是否为空或者全为空的情况

 function CheckEntry() {
                var flag
= true;
                var entryArray
= new Array();

                var txtCompanyCode
= $('<%= txtCompanyCode.ClientID%>').value;
                entryArray[
0] = txtCompanyCode != '';

                var txtCompanyName
= $('<%= txtCompanyName.ClientID%>').value;
                entryArray[
1] = txtCompanyName != '';

                var txtMobile
= $('<%= txtMobile.ClientID%>').value;
                entryArray[
2] = txtMobile != '';

                entryArray = CheckEntryForPassengerID(entryArray, 3);

                for (var i = 0; i < entryArray.length; i++) {
                   
if (entryArray[i] == false) {
                        flag
= false;
                       
break;
                    }
                }
               
if (flag == false) {
                    trEntryWarning.style.display
= "block";
                }

               
return flag;
            }

增加一个:遍历页面指定input ,进行录入为空检查

参考:javascript客户端遍历控件和怎么获取父容器对象

          //Check Entry For Passenger ID
           function CheckEntryForPassengerID(entryArray, flag) {
               var inputs = document.getElementsByTagName("input");
               for (i = 0; i < inputs.length; i++) {
                   if (inputs[i].type == "text" && inputs[i].id.indexOf("txtIDNumber") >= 0) {
                       entryArray[i + flag] = inputs[i].value != '';
                   }
               }
               return entryArray;
           }

JS包含关系

用indexOf()方法

如果返回>=0则表明包含,否则不包含

var a="TestHelloWord";

document.write(a.indexOf("Hello"));

66.关于js

是关于js的,但是可以延伸到任何静态对象中
情况是这样的,如果你在页面里引用了一个js,并且在服务器端做了cache,让用户第二次访问开始后就不需要反复下载这个js
但是问题就来了,如果你更新了这个js的版本,而服务器的清缓存的效果不明显,导致新js上线后用户仍然看不到最新效果
更严重的情况是原先的js可能产生致命性的bug,你的新JS就等着上线救火用的,这个时候怎么办呢
有两种办法解决
第一种是把js改名后,在程序里也修改这个js的引用地址,强制浏览器去重新验证静态文件的最后修改时间戳
第二种办法
在程序引用JS的地方写成如下的形式:
<script type="text/javascript" src="http://www.domain.com/js/myJS.js?a=1 /script
用一个QueryString放在URL后,这个a=1我只是举一个例子,你完全可以用一个随机数去代替a
这样做的好处就是让浏览器尽可能的不缓存这个JS
这是昨天XX在遇到google被封杀后整个XX频道都打开很慢甚至打不开的情况下
我们研究后发现就是因为引用了一个google的js引起的问题
但是服务器作了一个30天的缓存
我想了一个办法就是第二种办法
解决了这个问题
你如果在今后的项目遇到类似的问题也可以试试看这种办法

这种办法不仅对引用JS有效,对css,jpg,gif等等一系列静态文件都有效果

65.把ListBox的Text赋值TextBox

  //Select Value
            function SelectValue() {
                var ListBoxObject = document.getElementById('<%= lbCompanyName.ClientID%>');

                var txtvalue = document.getElementById('<%= txtCompanyName.ClientID%>');

                var ListIndexValue = ListBoxObject.selectedIndex;
                var ListBoxSelectedValue = ListBoxObject.options[ListIndexValue].text;

                var varValue = ListBoxSelectedValue;

                if (txtvalue.value.indexOf(varValue) < 0) {
                    if (txtvalue.value == "") {
                        txtvalue.value = varValue;
                    }
                }
            }

64.获取GridView中RowCommand的当前索引行 http://www.cnblogs.com/qqnnhhbb/articles/1312791.html

63.Web.config自定义节点configSections http://www.cnblogs.com/huc87/archive/2009/05/06/1450981.html

62.Asp.Net 页面执行顺序 http://www.cnblogs.com/cxy521/archive/2008/01/22/1048864.html

61.SmtpClient 身份验证失败(authentication failed) 的原因分析 http://www.cnblogs.com/sjcatsoft/archive/2009/06/06/1497772.html

60. MasterPage动态加载UserControls

1  for ( int i = 0 ; i < PNRFlightInfoList.Count ; i++ ) {
2                         JourneryInfoUserControl ucJourney = this.Page.LoadControl ( Settings.Default.UCJournery ) as JourneryInfoUserControl;
3                         ucJourney.PNRFlightInfo = PNRFlightInfoList[i];
4                         ucJourney.PNRFlightInfo.Segment = ( i + 1 ).ToString ();
5                         this.pJourneyInfo.Controls.Add ( ucJourney );
6                     }
7 
8 Settings.Default.UCJournery:
9 ~/UserControls/InputOrderInfo/PassengerInfoUserControl.ascx

59.去掉以下数据中的空格,并把空格替换成","

5.  KA893  S   SU02AUG  PVGHKG          HK4               1530            1810  SEAME 

6.  CX785  S   MO03AUG  HKGDPS          HL4               1005            1450      E

7.  CX784  S   FR07AUG  DPSHKG          HL4               1600            2045    E

8.  KA876  S   MO10AUG  HKGPVG          HK4               1000            1230     E

结果:5. ,KA893,S,SU02AUG,PVGHKG, HK4,1530,1810,SEAME,

if (typeof (document.getElementById("txtPNRFlight")) != "undefined") {
                var pnrFlight = document.getElementById("txtPNRFlight").value;
                pnrFlight = pnrFlight.replace(/(^\s*)|(\s*$)/g, '');
                pnrFlight = pnrFlight.replace(/\s+/g, "-");
                pnrFlight = pnrFlight.replace(/([^0-9a-zA-Z])\1+/g, ',');
                pnrFlight = pnrFlight.replace(/-/g, ',')
                document.getElementById("hfPNRFlight").value = pnrFlight;
            }

58.MS SQL Server 2005网络服务器配置方法
http://www.diybl.com/course/3_program/c++/cppjs/2008822/136969.html

57.Linq to Entities的验证框架

http://itsusony.spaces.live.com/blog/cns%2119E8A9605219DE15%211104.entry

56.浅拷贝和深拷贝

http://blog.magustest.com/blog/net/serialize-deserialize-implement-deep-copy/

http://www.cnblogs.com/Roping/archive/2009/05/13/1455880.html

55.JS  Invoke Code Event

参考:

http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx

http://blog.csdn.net/aboutblog/archive/2006/09/27/1293926.aspx

http://topic.csdn.net/t/20021115/15/1179762.html

http://www.mscto.com/dotnet/2008121118408.html

54.WebSlice 话题

<div>

<div id="slice1" class="hslice">

       <h2 class="entry-title">XXX</h2>

       <div class="entry-content">

          //在这里添加自定义的内容

       </div>

</div>

</div>

以上这段代码,如果想运行时,必须运行在IIS之上;不然的话,会没有WebSlice效果.

资源:

http://www.dotblogs.com.tw/code6421/archive/2009/04/17/8036.aspx

http://msdn.microsoft.com/zh-tw/ie/dd366103.aspx

53.WebService 话题(随便谈谈,记记)

Webservice

1.它是一种无状态的架构

2.设计时要考虑:性能与扩展的取舍;性能是一项功能,在开发中,必须重视它。

Session话题

Session只是针对于Web,值存储于Http中

1.如果WebSerivce要实现Session的存储,方法如下

[WebMethod(true)]

Public int Count()

{

Int temp =(int)Session["counter"];

Temp++;

Session["counter"] = temp;

Return temp;

}

2.如果WinForm要实现类似Session的存储,如何做呢?

任何Server端的技术,那Server和Client之间都是需要传递Cookie;

那Cookie主要作用:就是存储着SessionID,然后凭着SessionID去找到后台相对应的Session,那IE本身就可以处理Cookie;而应用程序一般是不会自动处理Cookie的。那如何实现呢?

可以Using System.Net;

CookieContainer cc= new CookieContainer();

Private void btn_click()

{

Localhost.Service t = new WSClient.localhost.Server();

t.CookieContainer = cc;

t.Count();

}

开发Webserivce一般不是建议使用Session,因为做事会比较多。一般做无状态。

Claim-Check模式:Webservices+MSMQ

http://www.codeproject.com/KB/XML/MTOMWebServices.aspx

SOAPMSMQ-开源软件

http://www.codeproject.com/KB/webservices/soapmsmq_wse3.aspx

image

随记系列:

 

      Asp.net 随记 Part2 (31- 52) [更新于2009/04/30]

      Asp.net 随记 Part1 (1- 30)

原文地址:https://www.cnblogs.com/RuiLei/p/1452916.html