Monday 18 February 2013

Center an element on the screen using jQuery



    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

 This is how you use it:  $('#window').center();

The above method will show the control @ center of the Window.

Sunday 17 February 2013

How to resize a website dynamically as per the window size

Today I got some requirement to re-size the some website that should doesn't have scroll bar and need to adjust dynamically as per the window size.

To do that you need to do it JQuery or CSS. I am posting here how you will do it in JQuery.

Just put this script in the page which you want to adjust its size.

<script type="text/javascript">
    $(document).ready(function () {
        Resize();
    });
    

 $(window).resize(function () { Resize(); location.reload(true); }); // when the window get re-sized
   
    function Resize() {
        var height = window.innerHeight ? window.innerHeight : $(window).height();
        height = height - 96; // Height of the Logo and the Footer is 96px so it is deducted.
        $("#leftNav").height(height);
    }
</script>


Here i am concerned about the height. I you want to resize with width also you can use $(window).width().

Note: Be cautious if you are still want to work the code in IE7 the do remember the following things, you need to deduct the view port


    if (jQuery.browser.msie) {
        if(parseInt(jQuery.browser.version) == 7) {
            viewportHeight -= 3;
        }
    }

    if($('#leftNav').height() > viewportHeight) {
        $('#leftNav').height($('#leftNav').height() - viewportHeight);
    }

    if($('#leftNav').height() < viewportHeight) {
        $('#leftNav').height(viewportHeight - $('#leftNav').height());
    }
 

Friday 1 February 2013

How to get all the Emails as Comma separatesd string in Sql Server.

SQL Server provides a function named Coalesce to do the task to join all the column value by comma separated string.

The Query is below:
Go
Declare @strEmail varchar(max)

SELECT @strEmail=coalesce(@strEmail+',','')+[Email]
       FROM Users      
print @strEmail  

Images are not updating in the IE on updating the Image file in websites using asp.net

This is a situation that occurs to each and every web developer who is developing the website.
Being a web developer using Microsoft .Net Framework i found this issue almost every next user it has. So, there are lot of solutions to this problem but I had found one of them is to be a very fine for the website  I am developing.


These are Some of the solutions that peoples nearby told me and some I find out in googling.

1) You need to remove the cache while updating the record, so the previous image is removed from the cache.

2)Force loading the web-page once image  is updated.

3) Load the image asynchronously only as per the current time.

However I like the last solution, i.e. is as below:

solution:
<img alt="Image" id="imgApp" src="@Url.Content("~/Images/Thumbnails/Apps/" + Model.App.ID + ".png?version=" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture))"

I had done this thing in mvc3 but you can do it any language.