adsense

Tuesday, December 10, 2019

Replace last charactor

I had a requirement where I need to replace all occurrences of \ in end of a string.

Regex helped me to achieved the expected result. The code for this is as shown below.

Regex.Replace(txtDomain.Text.Trim, "/+$", "")


Cheers
Samitha

Monday, November 25, 2019

jQuery modal Close contains additional text

if you are using jQuery modal you might see that the modal close icon has Close text alongside it.

This can be fixed using a simple css as displayed below.

<style type="text/css" >

.ui-button-icon-only {
   text-indent: -9999px;
}

</style>

Cheers
Samitha

Thursday, November 14, 2019

The CodeDom provider type “Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider” could not be located

You might have encountered above error when trying to run a Asp.net MVC project.

The cause of this issue is version changes in DotNetCompilerPlatform.dll. Check your web.config and make sure you have latest version as displayed below.

 <system.codedom>
         <compilers>

             <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />

             <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
         </compilers>

     </system.codedom>

Cheers
Samitha

Friday, October 18, 2019

Including js file

We can uses jQuery to import, include or require a js file within another js as shown below.


$.getScript("filename.js", function(){

   alert("filename.js loaded.");

});

Cheers,
Samitha

Tuesday, September 17, 2019

Chrome missing layout options in print preview

When trying to print a website in Chrome, you might see that print preview does not display the layout options to select.

This can be cause by two things.

1.Setting a custom @page size declaration in the Print  CSS
2. Integration of bootstrap


In both the above cases a custom @page size is given in the Print CSS and make sure you have set size: auto;  as shown below to resolve the issue.

@media print {
    @page {
        size: auto;
    }
}

Cheers,
Samitha

Tuesday, August 27, 2019

asp.net override style of an iframe

We can use jQuery to style the body or an element in an IFRAM E as shown below.


<script type="text/javascript">

$('#iframeID').load( function() {
    $(#'iframeID').contents().find("head")
       .append($("<style type='text/css'>  .className{display:none;}  </style>"));
});

</script>

Cheers,
Samitha

Friday, August 16, 2019

Remove resize grip on multiline textboxes

We can use css to easily remove the resize grip shown on multi line text boxes as shown below.

<style type="text/css">

textarea {
   resize: none;
}

</style>

Cheers,
Samitha

Wednesday, July 31, 2019

Restrict special characters

You can use JavaScript key press event to restrict special characters as shown below.

<script type="text/javascript">

 //this event can be attached in pageLoad or DOM Ready
function pageLoad() {

 var specialCharsArray = [61, 62, 33, 36, 64, 35, 37, 94, 38, 42, 40, 96, 126, 40, 41, 43];
//this array can be used to specify all the special characters

//the element can be an id of a textbox or in general input type=text
                element.bind("keypress", function (event) {
                     //check array
                    if ($.inArray(event.which, specialCharsArray ) != -1) {
                        event.preventDefault(); //prevent default event handle
                    }
                });

}
</script>



Use this link to test key code values.

Cheers,
Samitha

Wednesday, June 26, 2019

Visual Studio 2017 and SQL Server 2017 Installation issues

If you have decided to migrate to Visual Studio 2017 or later editions, there are few thing that will ensure a smooth installation and a working environment without much hassle.

Installing  SQL Server 2017 before installation of Visual Studio 2017 will ensure that SQL Server 2017 is install without an error..

If you have installed Visual Studio 2017 first  then the SQL Server 2017 setup will be failed with exit code 1638.

To resolve this uninstall the Microsoft Visual C++ 2017 redistributable as shown here.

In addition you will receive following error when trying to open SSMS.

Cannot find one or more components. Please re install the application

This can be resolved by

1. Reinstall the VS 2015 Shell (using Visual Studio 2017 setup)
2. Try to reopen SSMS. It if still fails try reinstalling SSMS.

Cheers,
Samitha

Monday, June 10, 2019

Resolving Maximum request length exceeded error

You might encounter Maximum request length exceeded error when you try to upload large files or perform web requests that fetch large chunks of data.


This error commonly raised by IIS as the default upload file size or request size is only 4MB.
There are two settings in the web.config that determined the request length. The following settings will increase the request  up to 100 MB.
 
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="102400" />
   </system.web>
</configuration>
 
&lt;system.webServer>
   &lt;security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
   </security>
</system.webServer> 
 
Please note that maxRequestLength is measured in Kilobytes 
and maxAllowedContentLength is measured in bytes.
 
 
Also note that this can be configured for the URL 
that performs the file upload/ request.
 
e.g.
 
<location path="Documents/Uploads">
<system.web>
    
   <httpRuntime maxRequestLength="102400" />
  </system.web>
  <system.webServer>
   <security>
     <requestFiltering>
       
        <requestLimits maxAllowedContentLength="104857600" /> 
      </requestFiltering>
    </security>
  </system.webServer>
</location> 

Cheers,
Samitha 
 

Wednesday, May 22, 2019

Visual Studio compilation issue "Attempted to access an unloaded AppDomain"

When trying to compile  the project you might encounter following error.

Attempted to access an unloaded AppDomain

Follow these steps to solve this issue.
  • Delete all the temporary files.
  • Restart Visual studio.
  • Clean your project solution.
  • Rebuild  and run the project .


Cheers
Samitha

Monday, May 6, 2019

Preventing multiple button clicks

There are scenarios when we need to disable a button to prevent multiple form submits. There can be many other ways, but following one tested and working for me.
Even though it is a kind of hack, it the easy way to achieve what needs to be happened

HTML

<asp:Button ID="btnSave" class="btn btn-sm" runat="server" Text="Save"  OnClientClick="DisableBtn(this);"  UseSubmitBehavior="false" />

JavaScript

<script type="text/javascript">

 function DisableBtn(btn) {
    btn.setAttribute('disabled', 'disabled');
   
    btn.click();

  }

</script >

Regards,
Samitha

Wednesday, May 1, 2019

jQuery working with paste

Following jQuery code can be used to catch the paste on an input and do some manupulation to the data pasted.

<script type="javascript">
   function pageLoad(){ //or you can use DOM Ready
 
       $('textarea').bind('paste', function () {
               var this= $(this);
                var orig = self.val();

                setTimeout(function () {//to chech the diffetence between pasted and original text
                   
                    if(this[0].value!==orig  ){
                        //more code
                    }
               });


});

  }
</script>

Cheers,
Samitha

Thursday, April 25, 2019

document ready not fired after post back

jQuery DOM ready tends to break if you are still working with update panels and the actual reason for that can caused by many things.

For me, it was calling DOM ready in Sys.Application.add_load(function); as displayed below.

 <script type="text/javascript">
         
Sys.Application.add_load(DomLoad);

function DomLoad() {
        $(function() {
                   //more code
        });
 }

 </script>

This also can be useful if you want to add multiple page loads scripts.

Read the following stack overflow post for more discussion on the same topic.

Cheers,
Samitha

Tuesday, April 16, 2019

TLS 1.2 suport in .Net 4.5 or above

Even thought Net 4.5 or above supports TLS 1.2, .Net default protocol is TLS 1.0. It is recommended to set the SecurityProtocol before any WebRequest calls.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

var url = "https://www.gmail.com";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

Setting SecurityProtocol before any WebRequest calls will make sure that response will not get following error when getting the response.

"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

Saturday, March 30, 2019

Targeting Microsoft Edge with CSS

CSS snippet follows can be used to target Edge browser

@supports (-ms-ime-align: auto) {
  .className {
        border: 1px solid;
  }
}

Please note that Edge is the only browser that supports this property.

Following snippet can be used to target both Edge/IE browsers.

_:-ms-lang(x),
.classNamer
{
  border: 1px solid;
}

Visit this link for more information,

Cheers
Samitha

Wednesday, February 27, 2019

CSS Accessing Elements using data attributes

When selecting elements in CSS, normally we user ID or class to select them. We can use data attribute in an element to select an element as shown below.

HTML

<div data-somename>
  Hi
</div>

CSS
[data-somename] {
color: red;
font-style: underline;

}

Cheers,
Samitha

Friday, February 15, 2019

read only radio input

A radio button can be easily disabled using "return false" on click as shown below.


<input type="radio" id="rbOptions" checked="checked" onclick="return false;"/>

Cheers
Samitha


Thursday, January 24, 2019

get RadioButtonList selected value.

You can use jQuery / JavaScript to get the selected value of a RadioButtonList . jQuery provides much more simpler approach as shown below.

jQuery
var selectedVal = $('#<%= RadioButtonList.ClientID %> input:checked').val();

JavaScript

var radioList= document.getElementById("<%= RadioButtonList.ClientID %>");
 var options= radioList.getElementsByTagName("input");
 var selected;
 for (var i = 0; i < options.length; i++) {
      if (options[i].checked) {
          selected = options[i];
          break;
       }
  }
  if (selected) {
       alert(selected.value);
  }

Regards,
Samitha

Wednesday, January 9, 2019

jQuery find element in a table

jQuery can be used to find an element inside a table easily as shown below.

var td = $("#tbIntervalos").find("#tdId");

cheers
Samitha