Calling jQuery on code behind with if condition
<p>I want to call a jquery on my code behind page when the condition is true.</p>

<p>My jquery is mentioned below which includes an array and two functions i.e hideAllmessage and showMessage. By default all messages will be hidden and if any condition is met , success , error , info , warning message will be displayed. Its a plugin which I have searched and want to implement. My code is mentioned below:</p>

<p>JQUERY FUNCTION</p>

<pre><code>var myMessages = ['info', 'warning', 'error', 'success']; // define the messages types         
function hideAllMessages() {
    var messagesHeights = new Array(); // this array will store height for each

    for (i = 0; i &lt; myMessages.length; i++) {
        messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
        $('.' + myMessages[i]).css('margin-top', -messagesHeights[i]); //move element outside viewport      
    }
}

function showMessage(type) {
    $('.' + type + '-trigger').click(function () {
        hideAllMessages();
        $('.' + type).animate({ marginTop: "0" }, 500);
    });
}

$(document).ready(function () {

    // Initially, hide them all
    hideAllMessages();

    // Show message
    for (var i = 0; i &lt; myMessages.length; i++) {
        showMessage(myMessages[i]);
    }

    // When message is clicked, hide it
    $('.message').click(function () {
        $(this).animate({ marginTop: -$(this).outerHeight() }, 500);
    });
});
</code></pre>

<p>CODE BEHIND</p>

<pre><code>ClientScript.RegisterStartupScript(Page.GetType(), "validation", "&lt;script language='javascript'&gt;showMessage('error')&lt;/Script&gt;");
</code></pre>
