Thursday, January 21, 2016

asp.net textbox yellowing in Chrome

I came across this issue when working with textboxes (auto fill on)   and tested on chrome browser. The textboxes are rendered with a yellowish background color.

This can be resolved in two ways.

1. Using CSS
 input:-webkit-autofill
    {
    -webkit-box-shadow: 0 0 0px 1000px white inset;
    }

2.Using jQuery
if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
$(window).load(function(){
    $('input:-webkit-autofill').each(function(){
        var text = $(this).val();
        var name = $(this).attr('name');
        $(this).after(this.outerHTML).remove();
        $('input[name=' + name + ']').val(text);
    });
});}

Detailed discussion can be found here.

Cheers,
Samitha

Monday, December 28, 2015

Asp.net textbox allow < charactor to be saved

Normally, saving special characters such as < or > require special configuration settings to be enabled in web.config file and in the page itself.


1) Disable request validation in the page

<%@ Page title="test" .... ValidateRequest="false" %>

2) Set requestValidationMode in Web.config


      



This solution could expose unexpected security threads.  Jquery provides a nice workaround to overcome this issue by escaping < and > characters as shown below.

 function validateTxt() {
    $("textarea, input[type='text']").change(function () { //replaces in all text areas and textboxes
      html = $(this).val(); //get the value
      //.replace("a" , "b")  works only on first occurrence of "a"
      html = html.replace(/< /g, "<"); //before: if there's space after < remove
      html = html.replace(/
      $(this).val(html); //set new value
   });
}

$(function () {
      validateTxt();
});
More discussion regarding the topic can be found here.

Cheers,
Samitha

 

Friday, November 20, 2015

IE11 compatibility mode off doPostBack and PageRequestManager undefined

There seem to be a bug in the browser definition files that came with .NET 2.0 and .NET 4.

This issue can be fixed by installing following hot fix for .net framework 4.0.

If you are deploying the asp.net application this should be installed in the machine where the application is deployed.

Regards,
Samitha

Wednesday, November 18, 2015

SQL Search

Searching for a specific text used in SQL objects can be made easy with the use of Redgate's SQL Search.

Even though SQL server provides queries for finding texts or columns this tool provides you much more flexibility.

Read following link for more information and download.

Cheers,
Samitha

Friday, October 30, 2015

Detect IE compatibility mode and version using JavaScript

Even though it is not recommended, following Javascript can be used to detect the IE compatibility mode.


// Create new object

var ieUserAgent = {
init: function () {
 
var ua = navigator.userAgent;
this.compatibilityMode = false;

    if(ua.indexOf("MSIE") == -1){
        this.version = 0;
        return 0;
    }

    if(ua.indexOf("compatible") == -1){
        this.compatibilityMode = false;
        return 0;

    }else{
        this.compatibilityMode = true;
        return 0;
    }
}
};

// Initialize the ieUserAgent object
ieUserAgent.init();

Read this thread for more details of the script.

Cheers,
Samitha


Thursday, September 10, 2015

Scroll to a specified target using jQuery

There may be situations where you need to scroll a page or element to a specified target. jQuery provides .scrollTo() method to achieve the desired functionality.

This method is built in from jQuery v 1.9.X. If you want to use it in an earlier version of jQuery, you can use an extension method.

Read here for more information.

Cheers,
Samitha

Friday, August 14, 2015

Remove all HTML Tags in text

There mey be situations where you need to remove all the HTML tags in a text. You can use Javascript Regex to to achove the desired result as displayed below.


<html>
<head>
<script type="text/javascript">
function replacetags(){
var html = /(<([^>]+)>)/gi;
for (i=0; i < arguments.length; i++)
arguments[i].value=arguments[i].value.replace(html, "")
}
</script>
</head>
<body>
       <form name="form1">
<textarea class="comment"  name="comments" id ="comments"  rows=5 cols=50></textarea><br>
<input type="button" value="Remove Tags" onClick="replacetags(this.form.comments)">
</form>
</body>
</html>