Monday, December 21, 2015

Display jquery dialog in parent window

The example below is a simple way to display a dialog in the parent window from an iframe.
  • Include jquery and jqueryui into your parent window
  • After this you can access to the parent JQuery object within iframe
   <script type="text/javascript">
         $(document).on("click", "[id*=btnShowPopup]", function () {
            var $jParent = window.parent.jQuery.noConflict();
            var dlg1 = $jParent('#editGiveawayDialog');
              dlg1.dialog({
               title: "Display Dialog",
               width: 550,
               height: 300,
               zIndex: 10000,
                 buttons: {
                   Ok: function () {
                     dlg1.dialog('close');
                   },
                   Cancel: function () {
                     dlg1.dialog('close');
                   }
                  },
                   modal: true
               });
               return false;
           });
            </script>

Hope this helps! :)

Sunday, November 29, 2015

CS0122: 'System.Configuration.StringUtil' is inaccessible due to its protection level

In Visual Studio

File - Open - Website
GoTo: C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles
Open
Now open App_Code\WebAdminPage.cs
GoTo Line 989
Comment out the current text and paste
string appId = (String.Concat(appPath, appPhysPath).GetHashCode()).ToString("x", CultureInfo.InvariantCulture);


Simple Encryption and Decryption Class C#

For anyone looking for a simple encryption class using Rijndael algorithm, enjoy!
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;

public static class EncryptionUtils { public static byte[] GenerateKey() { RijndaelManaged provider = new RijndaelManaged(); provider.GenerateKey(); return provider.Key; } public static byte[] GenerateIV() { RijndaelManaged provider = new RijndaelManaged(); provider.GenerateIV(); return provider.IV; } public static string Decrypt(byte[] encryptedBytes, byte[] key, byte[] iv) { RijndaelManaged provider = new RijndaelManaged(); MemoryStream ms = new MemoryStream(); using (CryptoStream cryptoStream = new CryptoStream(ms, provider.CreateDecryptor(key, iv), CryptoStreamMode.Write)) { cryptoStream.Write(encryptedBytes, 0, encryptedBytes.Length); } return Encoding.UTF8.GetString(ms.ToArray()); } public static byte[] Encrypt(string value, byte[] key, byte[] iv) { RijndaelManaged provider = new RijndaelManaged(); byte[] valueBytes = Encoding.UTF8.GetBytes(value); MemoryStream ms = new MemoryStream(); using (CryptoStream cryptoStream = new CryptoStream(ms, provider.CreateEncryptor(key, iv), CryptoStreamMode.Write)) { cryptoStream.Write(valueBytes, 0, valueBytes.Length); } return ms.ToArray(); }

Saturday, October 10, 2015

Disable Search In Toolbar For Windows 10

If your like me and don't care to have a search bar directly adjacent to the Windows start menu button after installing Windows 10.  The steps below will show you how to remove it.


First, right-click on the up arrow as demonstrated in the snapshot below. Next, hover your mouse pointer over the "Search" (or "Cortana") option, then a submenu will appear.

Choose "Hidden" here to disable the taskbar search altogether, or select "Show icon" to reduce the search bar down to a small icon.Choose "Hidden" here to disable the taskbar search altogether, or select "Show icon" to reduce the search bar down to a small icon.



Congrats!!  You've removed the search bar.

Friday, July 10, 2015

Disable autocomplete in Chrome

Originally when I was given the task to disable autocomplete. I thought it would be no problem, but that was far from reality. I tried adding autocomplete="off" to the input tag but it continued to show in chrome. Although, it did seemed OK in IE and Firefox. After a few hours of frustration. I decided to use "false" as the value instead of "off" which resolved the issue. Below is a snippet of the working code. 


//Use this for IE
autocomplete="off"

//Use this for Chrome
autocomplete="false"


//Form Example
// You can also add it to the form so you won't need to add it individually.
<form id="form1">
<input id="txtName" type="text" autocomplete="false" />
<input id="txtEmail" type="text" autocomplete="false" />
<input id="btnSubmit" type="button" value="Submit" />
</form>

Change SA password in MSSQL 2008

USE Master
GO
ALTER LOGIN sa WITH PASSWORD = 'Set New Password'
GO
ALTER LOGIN sa WITH
      CHECK_POLICY = OFF,
      CHECK_EXPIRATION = OFF;


Handling Multiple JQuery Versions

Although I don't recommend it. If you've ever need to use multiple JQuery versions, then I hope this helps. I recently worked on a project that needed to use multiple JQuery plugins.


 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
 <script type="text/javascript" src="Scripts/simpleZoom.js"></script> 
<script type="text/javascript"> //Create new variable and set it to now conflict. var jQuery_1_9_1 = $.noConflict(true); //Now, anytime you use this version, you'll need to use this variable. $(function () { jQuery_1_9_1('#show').simpleZoom({ zoomBox: "#zoom", markSize: [120, 169], zoomSize: [240, 338], zoomImg: [480, 677] }); }); </script>

Saturday, January 10, 2015

Maintain JQuery Tab Active Position on PostBack C#

Recent, I decided to use the JQuery tabs in one of my projects.  I noticed really quickly that when I had a click event inside the tabs, it would return to the first tab.  Typically, you can use the AJAX UpdatePanel to handle partial PostBacks but in my case,  It wasn't updating correctly with other databound controls.  The snippet below will show you how to maintain your tabs on PostBack.


First, add your JQuery script tags in the head section.
<link href="../jquery-ui-1.11.1.custom/jquery-ui.min.css" rel="stylesheet"></link>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
Next, add this script inside the header to initiate your tabs.
<script>
    $(function () {
        $("#tabs").tabs();
    });
</script>
Next, add this script function to the bottom of the page. This script will get the value from the hiddenfield control after PostBack.
 <script type="text/javascript">
        $(function () {
            $("#tabs").tabs({
                activate: function () {
                    var selectedTab = $('#tabs').tabs('option', 'active');
                    $("#<%= hdnSelectedTab.ClientID %>").val(selectedTab);
                },
                active: <%= hdnSelectedTab.Value %> + ""
            });
        });
    </script>
Next, add this hiddenfield control. This will be used to set the active tab when the PostBack occurs.
<asp:hiddenfield id="hdnSelectedTab" runat="server">
</asp:hiddenfield>
Finally, set the value of the hiddenfield control to the appropriate tab. To reset the value, set the value to 0 when the page is not a PostBack.
protected void btnCalShipping_Click(object sender, EventArgs e)
        {
            hdnSelectedTab.Value = "1";
        }