Friday, December 6, 2013

To set date format globally in global.asax

using System.Globalization;
using System.Threading;

//...
protected void Application_BeginRequest(Object sender, EventArgs e)
{    
  CultureInfo newCulture = (CultureInfo)  
System.Threading.Thread.CurrentThread. 
CurrentCulture.Clone();
 
  newCulture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy";
  newCulture.DateTimeFormat.DateSeparator = "-";
  Thread.CurrentThread.CurrentCulture = newCulture;
}

Thursday, November 28, 2013

Css cracks for browsers

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}


/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }



/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */

Monday, June 10, 2013

To check open and active connections to sqlserver.

FOLLOWING SYNTAX WILL SHOW NO OF CONNECTIONS FOR EACH DATABASE.
 
SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame
 
 TOTAL CONNECTIONS.
SELECT 
    COUNT(dbid) as TotalConnections
FROM
    sys.sysprocesses
WHERE 
    dbid > 0 

GET MORE BY RUNNIGN FOLLOWING.

sp_who2 'Active'

Tuesday, June 4, 2013

Ajax client end life cycle.

// Hook up Application event handlers.
var app = Sys.Application;
app.add_load(ApplicationLoad);
app.add_init(ApplicationInit);
app.add_disposing(ApplicationDisposing);
app.add_unload(ApplicationUnload);


// Application event handlers for component developers.
function ApplicationInit(sender) {
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  if (!prm.get_isInAsyncPostBack())
  {
      prm.add_initializeRequest(InitializeRequest);
      prm.add_beginRequest(BeginRequest);
      prm.add_pageLoading(PageLoading);
      prm.add_pageLoaded(PageLoaded);
      prm.add_endRequest(EndRequest);
  }
  $get('ClientEvents').innerHTML += "APP:: Application init. 
";
}
function ApplicationLoad(sender, args) {
  $get('ClientEvents').innerHTML += "APP:: Application load. ";
  $get('ClientEvents').innerHTML += "(isPartialLoad = " + args.get_isPartialLoad() + ")
";
}
function ApplicationUnload(sender) {
  alert('APP:: Application unload.');
}
function ApplicationDisposing(sender) {
  $get('ClientEvents').innerHTML += "APP:: Application disposing. 
";

}
// Application event handlers for page developers.
function pageLoad() {
  $get('ClientEvents').innerHTML += "PAGE:: Load.
";
}

function pageUnload() {
  alert('Page:: Page unload.');
}

// PageRequestManager event handlers.
function InitializeRequest(sender, args) {
  $get('ClientEvents').innerHTML += "
"; $get('ClientEvents').innerHTML += "PRM:: Initializing async request. "; } function BeginRequest(sender, args) { $get('ClientEvents').innerHTML += "PRM:: Begin processing async request. "; } function PageLoading(sender, args) { $get('ClientEvents').innerHTML += "PRM:: Loading results of async request. "; var updatedPanels = printArray("PanelsUpdating", args.get_panelsUpdating()); var deletedPanels = printArray("PanelsDeleting", args.get_panelsDeleting()); var message = "-->" + updatedPanels + " -->" + deletedPanels + " "; document.getElementById("ClientEvents").innerHTML += message; } function PageLoaded(sender, args) { $get('ClientEvents').innerHTML += "PRM:: Finished loading results of async request. "; var updatedPanels = printArray("PanelsUpdated", args.get_panelsUpdated()); var createdPanels = printArray("PaneslCreated", args.get_panelsCreated()); var message = "-->" + updatedPanels + " -->" + createdPanels + " "; document.getElementById("ClientEvents").innerHTML += message; } function EndRequest(sender, args) { $get('ClientEvents').innerHTML += "PRM:: End of async request. "; } // Helper functions. function Clear() { $get('ClientEvents').innerHTML = ""; } function printArray(name, arr) { var panels = name + '=' + arr.length; if(arr.length > 0) { panels += "("; for(var i = 0; i < arr.length; i++) { panels += arr[i].id + ','; } panels = panels.substring(0, panels.length - 1); panels += ")"; } return panels; }

Thursday, January 17, 2013

Run single instance of app in c#

accepted
To run a single instance of application in C#. Following code snippet can be usefull.

bool createdNew;

Mutex m = new Mutex(true, "myApp", out createdNew);

if (!createdNew)
{
    // myApp is already running...
    MessageBox.Show("myApp is already running!", "Multiple Instances");
    return;
}