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;
  }
 
</script> 
 
Cheers,
Samitha 

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

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

2) Add this to Global.asax.cs

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

Regards,
Samitha


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):

ALTER AUTHORIZATION ON SCHEMA::db_datawriter TO 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.


Friday, July 14, 2017

Retrieve the uploaded file extension from JavaScript

Following java script unction can be used to get the extension of a uploaded file.

function getFileExtension(fileName)
{
  var extension = /^.+\.([^.]+)$/.exec(fileName);
  return extension == null ? "" : extension [1];
}

Cheers
Samitha

Tuesday, June 27, 2017

Enable/Disable button when checkbox clicked

This can be easily achieved using jQuery as displayed below.

//bind this event in pageLoad or Dom Ready

$("#chkAgree").click(function(e) {
  $("#btnSave").attr("disabled", !this.checked);
});

Regards,
Samitha

Friday, June 2, 2017

asp.net textbox Enter key press focus to next control

The default behavior when  pressing Enter key on textbox is to fire the form submit event.
 This default behavior can be overridden and force the input to be advanced to the next control as shown below.

<script type="text/javascript">
 
 function pageLoad(){
 //you can use the control id or class
    $("#<%=txtName.ClientID%>").keypress(function (event) {
                var Text = $(this).val();
                if (event.which == 13) {
                    event.preventDefault();
                    $("#<%=txtPwd.ClientID%>").focus();
                }
            });
 
     $("#<%=txtPwd.ClientID%>").keypress(function (event) {
                var Text = $(this).val();
                if (event.which == 13) {
                    event.preventDefault();
                    $("#<%=butnLogin.ClientID%>").focus();
                }
            });
 } 
 
</script> 
 
 


Thursday, May 25, 2017

Multiple ID and class seletor



CSS
#divTitle.Format {  }

#divTitle.Format { }

Above CSS rules looks identical but they serves different purposes. As a summary above rules can be described as follows.

First CSS rule will Select all elements with the class named Format that are descendants of the element with an ID of divTitle.

 Second CSS rule will Select the element which has an ID of divTitle and also a class name of Format.

So if you want to select a specific HTML element with a given id and class the second CSS rule will come handy.

More detailed discussion of the above topic can be found here.
 
Cheers
Samitha