清空-青空-晴空

首页‎ > ‎技术‎ > ‎

C# .NET


Cancel Enter key event

发布者:Bowen Gu,发布时间:‎‎2009-11-22 下午10:08‎

    function doClick(e, buttonName) {
        var key;
        if (window.event)
            key = window.event.keyCode;
        else
            key = e.which;

        if (key == 13) {
            var btn = document.getElementById(buttonName);
            if (btn != null) {
                btn.click();
            }
            if (window.event)
            {
                e.keyCode = 0;
                e.returnValue = false;
                return false;
            }
            else {
                return false;
            }
        }
    }

404 page not found

发布者:Bowen Gu,发布时间:‎‎2009-10-12 上午7:11‎

http://helephant.com/2009/02/improving-the-way-aspnet-handles-404-requests/

        <customErrors mode="On">
            <error statusCode="404" redirect="404.aspx" />
        </customErrors>

        <httpModules>
            <add name="ErrorModule" type="ErrorModule, App_Code"/>
        </httpModules>

ErrorModule : IHttpModule

    public void Init(HttpApplication context)
    {
        context.Error += context_Error;
    }

    #endregion

    void context_Error(object sender, EventArgs e)
    {
        var context = HttpContext.Current;

        var error = context.Server.GetLastError() as HttpException;
        if (error.GetHttpCode() == 404)
        {

            var config =
                (CustomErrorsSection)WebConfigurationManager.GetSection("system.web/customErrors");
            if (config.Mode == CustomErrorsMode.On ||
                (config.Mode == CustomErrorsMode.RemoteOnly && context.Request.Url.Host != "localhost"))
            {
                context.Response.StatusCode = 404;
                //Server.ClearError();
                if (config.Errors["404"] != null)
                    HttpContext.Current.Server.Transfer(config.Errors["404"].Redirect);
                else
                    HttpContext.Current.Server.Transfer(config.DefaultRedirect);
            }
        }
    }



asp.net membership connect to SqlExpress database

发布者:Bowen Gu,发布时间:‎‎2009-10-5 上午5:04‎

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:


解决方法:

删除App_Data目录,

往web.config里添加:

  <connectionStrings>
    <remove name="LocalSqlServer"/>
       <add name="LocalSqlServer" connectionString="Data Source=AAA;Initial Catalog=BBB;Integrated Security=True"
            providerName="System.Data.SqlClient" />
  </connectionStrings>

failed to open VSTS 2008 project file

发布者:Bowen Gu,发布时间:‎‎2009-9-19 上午12:41‎

把自带的Sqlserver 2005 express 版卸载后,所以的solution文件就打不开了

Project could not be opened because the Microsoft Visual C# 2008 compiler could not be created. QueryService for failed.

--》
devenv.exe /ResetSkipPkgs





VS2008Test

发布者:Bowen Gu,发布时间:‎‎2009-9-15 下午11:38‎

The location of the file or directory 'aaa.dll' is not trusted.
 
=>
 
unblock the dll

table td fixed height

发布者:Bowen Gu,发布时间:‎‎2009-9-15 下午11:37‎

http://www.blakems.com/archives/000077.html

.tbl {
table-layout:fixed;
border-top: 5px solid #333;
border-collapse: collapse;
background: #fff;
}
.tbl td {
border-bottom: 1px dashed #333;
padding: 2px 5px;
text-overflow:ellipsis;
overflow:hidden;
white-space:nowrap;

}


Reset Identity column in SQL Server

发布者:Bowen Gu,发布时间:‎‎2009-9-9 下午5:06‎

DBCC CHECKIDENT(TableName, RESEED, 0)

backgroundWorker1

发布者:Bowen Gu,发布时间:‎‎2009-9-4 上午8:08‎

        private void btn1_Click(object sender, EventArgs e)
        {
            SetControlStatusOnSearch(true);
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            backgroundWorker1.ReportProgress(i);
        }    

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            MessageBox.ShowMessage("Work complete");
        }

Custom Control ViewState

发布者:Bowen Gu,发布时间:‎‎2009-8-28 下午6:23‎

       [Browsable(true), Category("NewDynamic")]
        public int VirtualItemCount
        {
            get
            {
                if (ViewState["pgv_vitemcount"] == null)
                    ViewState["pgv_vitemcount"] = -1;
                return Convert.ToInt32(ViewState["pgv_vitemcount"]);
            }
            set
            {
                ViewState["pgv_vitemcount"] = value;
            }
        }

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

发布者:Bowen Gu,发布时间:‎‎2009-8-26 上午8:11‎

这样不会错:Response.Redirect(url);

这样会错:
        try
        {
            Response.Redirect(url);
        }
        catch (Exception ex)
        {       }

这样不会会错:
        try
        {
            Response.Redirect(url, false);
        }
        catch (Exception ex)
        {       }

‹ 上一页    1-10/50    下一页 ›

蛰伏是另一段旅程的开始,人生总有浮云蔽日时,若能善用时光,蓄劲待发,静待云轻日开,则生命的甘泉,终有奔涛流涌、万里清畅的一天。

MSN
   
MAIL
   
   

208 天前是
五一

228 天前是
太湖两日游