Thursday, June 11, 2015

Reset or Normalize User Code Stylesheet

Here i am going to talk about "User Code Style sheet". It is default style sheet of browser get applied on Dom elements if nothing is specified about how to handle elements appearance on page.


But it might get applied if the tags are not closed properly and will lead to different UI display.

Solution :

To resolve this issue we have 2 either to reset it or normalize stylesheet.

Reset CSS: (Get Reset Css)
Resets browsers defauts

Normalize CSS: 
Preserve useful browser defaults rather than erasing them. 
Normalize styles for a wide range of HTML elements.
Correct bugs and common browser inconsistencies. 
Improve usability with subtle improvements. 
Explain the code using comments and detailed documentation.

Note: Try to put it after all your style sheet to implement inherit property. 

Happy Living.....
Happy Concepts.....
Happy Coding.....

Friday, May 22, 2015

Enable Nuget packages in Visual Studio 2010

The NuGet is easier way to include dlls or other projects/utilities in your projects. If we aren't using it , in one way we are selecting some tough way to achieve something that can be implemented in straight forward way.

Open Visual studio in menu bar click on Tools-> Extension Manager

fig 1

It will open a new popup as shown below, In this popup you can see there isn't any Extension Manager installed. Once we install Nuget it will appear in this screen.

fig 2
Now we will do following steps:
1. Click on Online Gallery under Installed Extensions.
2. Type Nuget in search text box at right top corner
3. Now it will appear in middle area of window now click to Download.

fig 3
Now you will get another popup for installation read term and conditions and click on install.

fig 4

On completion of installation there will be a message box, close it.

fig 5

Once it get completed, Restart Visual Studio  you will able to see it under Installed Extensions.

fig 6

And its done. In next blog we will check how to use NuGet Package Manager.

Happy Living....
Happy Coding....
Happy Concepts....

Wednesday, November 5, 2014

Change Doc type to IE8 or IE8 Compatibility mode

Change Doc type to IE8 or IE8 Compatibility mode:

There are some old development that doesn't support in newer version of IE and Chrome. So best option is to make changes in code work for latest IE versions and Chrome. But this is the case not always possible for example previous code was built using third party controls (Infragistics in my case) to make it work with Newer version of IE we need upgraded version on Infragistics and it involves addition cost of licensing.
One other work around if it is possible to support only IE  browser than we can use solution suggested below: (BUT it is not best solution)

 <title> My Page</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">

<meta http-equiv="X-UA-Compatible" content="IE=8">

Note : Make sure to use meta tag just after title tag otherwise it wont work.

Happy Coding...
Happy Concepts...
Happy Living....

Monday, May 5, 2014

Convert local datetime to UTC or Universal data time and UTC to local datetime

--Steps required before performing conversion:


Declare @TimezoneOffset int=0

-- variable will hold the timezone difference in minutes

set @TimezoneOffset =  DATEDIFF(Minute, GETUTCDATE(), GETDATE())

--Now we have localtimezone difference with UTC.

--Convert Local datetime to UTC:-

Declare @LocalDatetime datetime= GetDate()

Declare @UTCDatetime datetime =null

select  @UTCDatetime= DateAdd(Minute,-@TimezoneOffset,@LocalDatetime)

--Convert UTC to Local datetime :-

 Declare @ConvertedLocalDatetime datetime=null

select @ConvertedLocalDatetime= DateAdd(Minute, (@TimezoneOffset),@UTCDatetime)

select 'LocalTime:-',@LocalDatetime,'  UTC Datetime : ', @UTCDatetime ,'ConvertedLocalDatetime : ', @ConvertedLocalDatetime

Monday, April 7, 2014

Download file using javascript/Jquery

On aspx page add this:

<iframe id="hiddenDownloaderForPdf" style="display:none" ></iframe>

on Javascript file:

function downloadFile (url) {
        var hiddenDownloaderForPdf= 'hiddenDownloaderForPdf'
        iframe = document.getElementById(hiddenDownloaderForPdf);
//if iframe isnt available create one dynamiclly
    if (iframe === null) {
        iframe = document.createElement('iframe'); = hiddenDownloaderForPdf; = 'none';
    iframe.src = url;

using jQuery:
function downloadFile (url) {
        var hiddenIFrameID = 'hiddenDownloaderForPdf'

       $('#'+ iframe).attr('src' ,url);

Happy Living.....
Happy Concepts.......
Happy Coding........

Way to rename table without changing references of Table

Some time problems are not that easy to resolve because we got stuck in our think box. But how can we think out of box if we sit in a cube( jokes apart).
Today we are faced an issue where we have to rename table name and add new column in it so that we can differentiate existing data with new added records. But it wasn't possible because this table is used as first table in joins.

for example :

id name description

Bid Xid Values

select * from tblX a
inner join tblB  b on 
and i am doing this kind of thing hundred of places in my SPs.

Now my requirement is something like that

Rename table to tblX to tblXYZ and add new column CategoryType.
Update all records with CategoryType 'X'

id name description category

 so for making existing code work i may need to change above queries like that:

select * from tblXYZ a
inner join tblB  b on 
where a.CategoryType='X'

but this isnt possible for me so what i can do?????


instead of changing queries in SP what we can do we can create  a new VIEW
with same name tblX and define it as :

select * from tblXYZ
where CategoryType='Y'

by using this VIEW we doesn't require to change SP's .

This is the best approach in fount till now ,, if there will anything new i'll let you know.

Happy Living.....
Happy Concepts.....
Happy Coding...........

Monday, July 22, 2013

Is Reflection breaks Encapsulation

"Today, I learn a big lesion  that what ever we know isnt surely only truth. We may know what is true but there may be other true that are different from what we know. And sometime no one tells us that what is truth either because they dont know them selves or we might be not a level to understand that."

Whatever i write down above is just what i felt about knowing that we can call or access private members of class regardless of that can break the concept of encapsulation.

So as i told you reflection can used to access private members.Let assume we have a class Cat.
For eg.

 public class Cat

        private int NoOfLegs = 4;

now we will use to reset the value of NoOfLegs using reflection.

   Cat c = new Cat();
            Type  t= typeof(Cat);

            t.GetField("NoOfLegs", BindingFlags.Instance | BindingFlags.NonPublic)
            Console.Write(t.GetField("NoOfLegs", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(c));

So myth creaked  that reflection cant access private members.

"So If some is saying that private members aren't accessible by outside you can prove him/her wrong".

As explained above encapsulation is a design technique to make design clean and structured. If some wants to take full responsibility by changing private members he is on risk of getting exception.
For eg someone can set value to null using reflection so our job as developer is to make sure we are handling null and throwing exception. As we cannt trust on other developers or user of providing expected inputs.
This solution is provided because we may need to test private member of our class.


Somehow Dynamic datatype is popular as alternative of reflection but it isnt. Dynamic datatype allows as to check property and fields are runtime. Some rules remain unbreakable like object of a class can access only public members of class.
So if someone is thinking to do something similar we did with reflection then he must be ready to get unhandled exception like RuntimeBinderException With msg"'RefdynEncApp.Cat.NoOfLegs' is inaccessible due to its protection level ".

Happy Living...
Happy Coding....
Happy Concepts...