Pages

Ads 468x60px

Social Icons

Featured Posts

Search

How to create page with header and iframe covering rest of the page

Thursday, 26 August 2010

A few times I needed to have a page where I have an iframe (I know, I know - it is bad design, but sometimes you need to sacrifice!) with header to the top. I tried many different CSS hacks, but could not get it right. Then I came around pageY(), tiny function created by John Resig (jQuery author), which helps to resolve this particular problem brilliantly:

    function ResizeIFrame() {
        var buffer = 40; //scroll bar buffer
        var height = document.documentElement.clientHeight -
pageY(document.getElementById('ifrm')) + buffer;
        height = (height < 0) ? 0 : height;
        $('iframe#ifrm').css('height', height + 'px');
    }

    function pageY(elem) {
        return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) :
elem.offsetTop;
    }


Where 'ifrm' is ID of iframe.

The only thing we need now is handing load and resize events:

    window.onload = window.onresize = ResizeIFrame;

This could not be simpler!

Passing list as parameter from AJAX request to MVC controller

Wednesday, 25 August 2010

I came across this recently when needed to pass array of selected values into MVC controller during Ajax request. Scenario was that on the page I had set of checkboxes and button. User can then make multiple choice selection and submit form using button. Html is something like:

[html]
<ul id="sampleList">
    <li><input type="checkbox" value="1" checked="checked" />text 1</li>
    <li><input type="checkbox" value="2" checked="checked" />test 2</li>
    <li><input type="checkbox" value="3" checked="checked" />test 3</li>
</ul>
<input type="button" id="submitButton" value="submit" />
<span id="spanResults"></span>
[/html]

Also in the application I have, let's say, "TestController". Within this controller I have "GetValue" method, that I want to concatenate input data into a string:

[CSharp]
public JsonResult  GetValue (List<string> id)
{
    return Json(id);
}
[/CSharp]


Then jQuery code to collect values of checked checkboxes and make Ajaxcall would be as following:

[JavaScript]
var items = new Array();
$('#sampleList li input:checkbox:checked').each(function() {
    items.push($(this).val());
});

$('#submitButton').click(function() {
    $.ajax({
        type: 'post',
        url: '/Test/GetValues',
        data: { id: items },
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(data) {
            $('#spanResults').text(data.join(','));
        },
        error: function(e) {
            alert(e.message);
        }
});
[/JavaScript]

This should hopefully put some light on "how on the earth do I pass list as parameters via Ajax to MVC".

How to drop all schema objects in MS SQL 2005

Tuesday, 10 August 2010

I needed to test my SQL implementation script that was a part of big SQL Server Data Warehouse release. For anybody who have ever done large SQL implementation fundamental question is always "Have I scripted everything that is needed?". So how to check if your implementation script contains all objects you require? Here is a few steps that helped me:

  1. Collate all individual scripts into one or more implementation script (I recommend having  one script per development, but it always depends on circumstances).

  2. Order your scripts so you know the sequence of running them. This is specifically important if there is dependency between objects created by different scripts.

  3. Create backout script for each implementation one and order them as well.

  4. Drop all objects that come into release. "How to drop all schema objects in one go?" - this is where it turns out to be priceless to have DBA in your team:


declare @schema varchar(200)
select @schema = 'MySchema'

select
'DROP ' + case
    when o.xtype = 'U' then 'TABLE'
    when o.xtype = 'V' then 'VIEW'
    when o.xtype = 'P' then 'PROCEDURE'
    when o.xtype = 'FN' then 'FUNCTION'
    end + ' ' + s.name + '.' + o.name as SQL
from
    sys.sysobjects as o
    join sys.schemas as s on o.uid = s.schema_id
where
    s.name = @schema and
    o.xtype in ('U','V','P','FN')
union all
select
'DROP SCHEMA ' + @schema

This will give you DROP statement for each table, view, stored procedure and user defined function in your schema, as well as schema itself. Just grab whichever statement you need and execute it!
 

Most Popular