Sunday, January 23, 2011

How does jQuery implement hide() and show()

By display: none
Not visibility: hidden


JQuery Source code:

hide: function( speed, easing, callback ) {
if ( speed || speed === 0 ) {
return this.animate( genFx("hide", 3), speed, easing, callback);

} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
var display = jQuery.css( this[i], "display" );

if ( display !== "none" ) {
jQuery.data( this[i], "olddisplay", display );
}
}

// Set the display of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
this[i].style.display = "none";
}

return this;
}
}

Saturday, January 22, 2011

Three ways for initialization tasks in Javascript: $(handler), Onload() and pageLoad()

1. pageLoad(), it is called for every partial postback. We should put JQuery event handlers in this function.

2. window.onload = function () {alert("onload");}

Onload() event will be called only after the DOM and associated resources like images got loaded


3. JQuery $(document).ready(handler)
jQuery's document.ready() event will be called once the DOM is loaded, it wont wait for the resources like images to get loaded

All three of the following syntaxes are equivalent:
  • $(document).ready(handler)
  • $().ready(handler) (this is not recommended)
  • $(handler)

Reference:
http://api.jquery.com/ready/




If useful, Consider making a donation to show your support.

Friday, January 21, 2011

How to solve No animation on GIF file if submit a form in html?

Solution: Need to load gif file just before submit by JavaScript/JQuery

<input type="button" class="button" id="process" name="cmdFinish" value="Confirm" />
<div id="processinfo" style="display: none">

<script type= "text/javascript">
$("#process").click(function() {
document.getElementById('processinfo').innerHTML = '<img src= "images/load.gif" /> <br/>Processing...';
$("#processinfo").show();
$("form:first").submit();
});
</script>

How to convert DataTable into anonymous type class list for LINQ

System.Data.DataTable table = dataSet.Tables[0];
var GridviewData = from oneRow in table.AsEnumerable()
  select new
  {
  ID = oneRow.Field<Int32>("ID"),
  Amount = oneRow.Field<decimal>("Amount"),
  Description = oneRow.Field<string>("Description"),
  DateTime = oneRow.Field<System.DateTime?>("DateTime"),
  };

Thursday, January 20, 2011

How to make form input button look like a regular href link?

style="border: 0; cursor: pointer; cursor: hand; background-color: transparent; text-decoration: underline;"