Thursday, January 18, 2018

Retrieve button value

You can use jQuery val() function to retrieve buttons' value as shown below.


<button class="btn1"  name="btn1" value="button1">


<script type="text/javascript">
    $(function() {
        $('.btn1').click(function() {

 This will display the value button1.


Wednesday, December 6, 2017

.NET Support for TLS 1.2

It seems that support for TLS 1.2 dependent on the .net framework version.

  • NET 4.6 and above. Supported by default.
  • .NET 4.5. TLS 1.2 is supported. The following code will make TLS 1.2 to be used as the default protocol.                                                                  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  • .NET 4.0. TLS 1.2 is not supported, but following code can be used as a workaround:
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
  • .NET 3.5 or below. TLS 1.2 is not supported.


Thursday, November 16, 2017

Removing XML Nodes from a XML Document

Following code can be used to remove a XmlNode with all the children nodes

      XmlDocument doc = new XmlDocument();
        doc .Load(MapPath("~/FileName.xml"));
        XmlNodeList selectedNodes = doc .SelectNodes("//SubNode");
       foreach (XmlNode node in selectedNodes )


Thursday, November 2, 2017

IIS error accessing WCF (HTTP Error 404.3)

When accessing a WCF service through browser, you  might have encountered following IIS error.

HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

This occurs due to a feature in IIS which is not turned on by default.

This issue can be solved through following steps.

  1. From Control Panel -> Programs and Features -? Turn Windows features on or off.
  2. Click.NET Framework 4.6 Advanced Services - WCF Services (actual framework version may change)
  3.  Select HTTP Activation
  4. Ok


Wednesday, October 4, 2017

jquery paste event

You can use the jQuery paste event on any textbox/editor as shown below. It is supported by all modern browsers.

Following example shows handling numeric values on key press and past.

 <script type="text/javascript">

 function pageLoad() {
  $("#controlID").on('paste, keydown', function e() {
        return isNumericKey(e);
function isNumericKey(e) {
    var charInp = window.event.keyCode;
        if (charInp > 31 && (charInp < 48 || charInp > 57)) {
            return false;
        return true;

Wednesday, August 30, 2017

Refused to display in a frame because it set 'X-Frame-Options' to 'DENY'

You might Sometimes encounter the error above when you are using iframes w to load resources outside from the domain.

This Issue can be fixed in two ways

1) Add this to web.config

      <add name="X-Frame-Options" value="AllowAll" />

2) Add this to Global.asax.cs

protected void Application_PreSendRequestHeaders()
 Response.AddHeader("X-Frame-Options", "AllowAll");
Please read this discussion in stackoverflow for a detailed discussion on the topic.


Wednesday, August 9, 2017

drop database user that owns a schema

First you will have to determine the schema's owned by a given user in order to  drop the user.

Execute the following query to determine the schemas owned by the user  named ‘user1’ .

SELECT name FROM sys.schemas
WHERE principal_id = USER_ID('user1');

When you run the query above, suppose you get db_datawriter as the schema owned by user (in this case user1)

Next step is to change the owner of the schema db_datawriter to some other user (e.g. dbo):


You will have to remove all the schemas to drop a db user. When the user has no schemas owned you can drop it.