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;"

Remote validation, a new feature in MVC 3 for single field server side validation

Common scenario like, you want to check a user name if exist before posting all of information to server.
Before MVC 3, this kind of validation can be implemented by either JQuery ajax calling an action in MVC or a web service in webform.

ASP.NET MVC 3 provides a mechanism that can make a remote server call in order to validate a form field without posting the entire form to the server