Add function into onbeforeunload
var unsavedChanges = false; window.onbeforeunload = function() { if (unsavedChanges) return 'You have unsaved changes!'; }
https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload
var unsavedChanges = false; window.onbeforeunload = function() { if (unsavedChanges) return 'You have unsaved changes!'; }
protected void Session_Start(Object sender, EventArgs e) { Session["init"] = 0; }http://msdn.microsoft.com/en-ca/library/system.web.sessionstate.httpsessionstate.sessionid.aspx
private void SetProviderConnectionString(string connectionString) { // Set private property of Membership, Role and Profile providers. FieldInfo connectionStringField = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic); if (connectionStringField != null) connectionStringField.SetValue(Membership.Provider, connectionString); FieldInfo roleField = Roles.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic); if (roleField != null) roleField.SetValue(Roles.Provider, connectionString); FieldInfo profileField = ProfileManager.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic); if (profileField != null) profileField.SetValue(ProfileManager.Provider, connectionString); }
http://msdn.microsoft.com/en-ca/library/bb763177(v=vs.90).aspx
public ActionResult QRImage(int id) { string url = string.Format("http://myevents.apphb.com/event/details/{0}", id); QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H); QrCode qrCode = qrEncoder.Encode(url); GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White); MemoryStream ms = new MemoryStream(); renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms); byte[] image = ms.ToArray(); ; return File(image, "image/png"); }
using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Threading; namespace RPNEvaluator { class RPNEvaluator { static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string rpn = "3 4 2 * 1 5 - 2 3 ^ ^ / +"; Console.WriteLine("{0}\n", rpn); decimal result = CalculateRPN(rpn); Console.WriteLine("\nResult is {0}", result); } static decimal CalculateRPN(string rpn) { string[] rpnTokens = rpn.Split(' '); Stackstack = new Stack (); decimal number = decimal.Zero; foreach (string token in rpnTokens) { if (decimal.TryParse(token, out number)) { stack.Push(number); } else { switch (token) { case "^": case "pow": { number = stack.Pop(); stack.Push((decimal)Math.Pow((double)stack.Pop(), (double)number)); break; } case "ln": { stack.Push((decimal)Math.Log((double)stack.Pop(), Math.E)); break; } case "sqrt": { stack.Push((decimal)Math.Sqrt((double)stack.Pop())); break; } case "*": { stack.Push(stack.Pop() * stack.Pop()); break; } case "/": { number = stack.Pop(); stack.Push(stack.Pop() / number); break; } case "+": { stack.Push(stack.Pop() + stack.Pop()); break; } case "-": { number = stack.Pop(); stack.Push(stack.Pop() - number); break; } default: Console.WriteLine("Error in CalculateRPN(string) Method!"); break; } } PrintState(stack); } return stack.Pop(); } static void PrintState(Stack stack) { decimal[] arr = stack.ToArray(); for (int i = arr.Length - 1; i >= 0; i--) { Console.Write("{0,-8:F3}", arr[i]); } Console.WriteLine(); } } }
function createBinaryString (nMask) { // nMask must be between -2147483648 and 2147483647 for (var nFlag = 0, nShifted = nMask, sMask = ""; nFlag < 32; nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1); return sMask; } var string1 = createBinaryString(11); var string2 = createBinaryString(4); var string3 = createBinaryString(1); alert(string1); // prints 00000000000000000000000000001011, i.e. 11 var bits=string1.split("");
Number.prototype.formatMoney = function (c, d, t) { var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; //Usage: (123456789.12345).formatMoney(2, '.', ',');
$('html').bind('keypress', function(e) { if(e.keyCode == 80 || e.keyCode == 112) { return false; } })
&
" and "<
" respectivelyArray values = Enum.GetValues(typeof(MyEnumType)); foreach (MyEnumType val in values) { var enumName = Enum.GetName(typeof(MyEnumType), val); }