Friday, March 06, 2020

Bootstrap 3 Prevent or Disable Closing Bootstrap Modal

Use HTML

<button type="button" id="MybtnPreventHTML" class="btn btn-primary" data-target="#MymodalPreventHTML" data-toggle="modal" data-backdrop="static" data-keyboard="false">Open Modal</button>
<!-- .modal -->
<div class="modal fade" id="MymodalPreventHTML">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Notification</h4>                                                            
</div>
<div class="modal-body">
Are you sure you want to continue?
</div>  
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>                                                                      
</div>                                          
</div>

Use Jquery


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Friday, August 28, 2015

Recompile the store procedure to improve the performance

One of our report runs under 2min in TEST environment, but over 10 min when deployed in production.  After days of research, it turns out all we need to do is to recompile the stored procedure.

Below is from MSDN:

When a procedure is compiled for the first time or recompiled, the procedure’s query plan is optimized for the current state of the database and its objects. If a database undergoes significant changes to its data or structure, recompiling a procedure updates and optimizes the procedure’s query plan for those changes. This can improve the procedure’s processing performance.

example:
USE AdventureWorks2012;
GO
EXEC sp_recompile N'Sales.Customer';
GO

https://msdn.microsoft.com/en-us/library/ms190439.aspx

Monday, August 17, 2015

Use camelCasing JSON

Add the following code in the WebApiConfig.cs file in the App_Start folder:

In the Register static method, add:

// Web API configuration and services
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

reference:
http://odetocode.com/blogs/scott/archive/2013/03/25/asp-net-webapi-tip-3-camelcasing-json.aspx

Wednesday, June 17, 2015

Bootstrap Themes

http://bootswatch.com/

https://wrapbootstrap.com

http://fontawesome.io/

Tuesday, June 09, 2015

MVC bootstrap Modal Dialog

starts with:  http://www.codeproject.com/Tips/826002/Bootstrap-Modal-Dialog-Loading-Content-from-MVC-Pa

Replacing Html.BeginForm with Ajax.BeginForm:  http://blogs.msmvps.com/craigber/?p=41

Fix the cache issue with Ajax.BeginForm:  http://www.leniel.net/2013/09/detecting-fixing-ajax-beginform-partial-view-stale-data.html

Monday, June 01, 2015

MVC data annotation on Password field

Below is the cheat sheet for the password field:


       
[Required]
[StringLength(255, MinimumLength=8)]
[DataType(DataType.Password)]
[RegularExpression(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\da-zA-Z])(.{8,15})$", ErrorMessage = "Password must contain at least 1 number, 1 uppercase letter, and 1 special character.")]
public string Password { get; set; }

 

^                   #Beginning of expression
(?=.*\d)            #At least one digit
(?=.*[a-z])         #At least one lower case
(?=.*[A-Z])         #At least one upper case
(?=.*[^\da-zA-Z])   #A non-alphanumeric character
(.{8,15})           #Allow between 8 and 15 characters
$                   #End of expression

Good website to find a starting point for Regular Expression:  http://regexlib.com/

Friday, March 23, 2012

Increase performance by adding NONCLUSTERED INDEX

Got a call from a client reporting an issue that is randomly occurred. after looking into the log file, I found one method took over a min to complete. The code shows only a simple select statement with where clause on "sentby" column. This column is a "nvarchar" and the table itself has over 1 million records.

Here is what I learned when I trying to fix this issue:

1. use "varchar" instead of "nvarchar". only use "nvarchar" when you have different languages in the same column! if you look at the sql execution plan ( sql -> display estimated ececution plan), search "nvarchar" does an index scan and "varchar" does index seek. index seek is orders of magnitude faster than a scan!

2. no index is set on "sentby" column. It won't be an issue in the small table (sql does index scan on small table), but it will impact performance when data grows. I used the script below to add a NONCLUSTERED INDEX on this column.

CREATE NONCLUSTERED INDEX IDX_MyMessageTable ON dbo.MyMessageTable
(
SentBy
)

after the index is created, the 1 min search time is down to under a second.