UserControl as a DLL made easy

To create controls in asp.net there are two options available.

  • Custom Controls
  • User Controls

User controls cannot be compiled into a dll and redistributed while a custom control can be compiled into a dll. But a custom control does not have separate files to hold your markup and code which user controls have.

If I can have separate files for markup and code in custom controls, its the best option for creating redistributable custom controls. This will make my design clean as I will achieve a clear separation of concern between my presentation (markup) and behavior (code).

Currently this option is not available in asp.net but there is a nice article to achieve this. The code is also clean and does not pass as a hack but a proper way to create custom controls.

  • Share/Bookmark

Healthy body healthy mind

Key to be very successful in life is to have a very well developed mind, which is able to think good and do good. Like any radioactive element, mind if contained in a good container can be very useful. Our body is the container and the mind is the contained.

Having a good body thus becomes a necessity for people trying to develop their mind. Take good care of your health and rest is taken care of to a good extent.

Eat healthy and stay fit. ;)

  • Share/Bookmark

HTML Encode Text in JavaScript

There are many ways of HTML encoding text in JavaScript. You may use string replacement using RegEx or simply hardcode replacements. These approaches help solve the purpose but make the code bloated and difficult to maintain. There is one clean way of achieving this.

function HTMLEncode(value){
     var div = document.createElement(“DIV”);
     var textNode = document.createTextNode(value);
     div.appendChild(textNode);
     return div.innerHTML;
}

The above code will html encode your text in a cleaner and faster way

  • Share/Bookmark

Wrap long lines using CSS and JavaScript

I had this annoying problem of long unwrap-able lines breaking my website layout. After experimenting many fixes I finally settled on the following fix.

<script type="text/javascript">
     $(function(){
          $(".wrap").each(function(){
               $(this).html(
                    $(this)
                         .text()
                         .replace(/([^\s-]{5})/g, "$&&shy;")
                    );
          });
     });
</script>

The above code uses jQuery and Regular Expression to wrap text in tags which have the class “wrap” by adding &shy; after every 5 characters in a long word. For more information on &shy; refer the references section below.

References:

  • Share/Bookmark