Wednesday, July 27, 2011

How to center a div by jQuery



jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}


$(element).center();

http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen

Model Metadata and Validation Localization using Conventions

http://haacked.com/archive/2011/07/14/model-metadata-and-validation-localization-using-conventions.aspx

Friday, July 22, 2011

A Forgotten Story - Ajax in ASP.NET using JavaScript

http://blogs.cametoofar.com/post/raw-or-plain-ajax-in-aspnet-using-javascript.aspx


<script type="text/javascript">
    function sendViaAjax() {
 
        // Build URL to make Ajax call
        var url = "Test.aspx?name=" + document.getElementById("txtName").value;
 
        // Creates an Ajax call object
        var xmlHttp; = new XMLHttpRequest();
 
        // Specify URL to connect
        xmlHttp.open("GET", url, true);
 
        // Callback function to handle response from Server
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    alert(xmlHttp.responseText);
                }
            }
        };
 
        // Send Ajax request to Server
        xmlHttp.send();
    }
</script>

protected void Page_Load(object sender, EventArgs e)
{
    string ajxValue = "Hello " + Request.QueryString["name"] + " !";
 
    Response.Write(ajxValue);   // Write the Response
    Response.End(); // End Response
}

Thursday, July 21, 2011

Monday, July 18, 2011

Worse is Better

http://www.jwz.org/doc/worse-is-better.html


The worse-is-better philosophy is only slightly different:

  • Simplicity-the design must be simple, both in implementation and interface. It is more important for the implementation to be simple than the interface. Simplicity is the most important consideration in a design.
  • Correctness-the design must be correct in all observable aspects. It is slightly better to be simple than correct.
  • Consistency-the design must not be overly inconsistent. Consistency can be sacrificed for simplicity in some cases, but it is better to drop those parts of the design that deal with less common circumstances than to introduce either implementational complexity or inconsistency.
  • Completeness-the design must cover as many important situations as is practical. All reasonably expected cases should be covered. Completeness can be sacrificed in favor of any other quality. In fact, completeness must sacrificed whenever implementation simplicity is jeopardized. Consistency can be sacrificed to achieve completeness if simplicity is retained; especially worthless is consistency of interface.

Image select list by jQuery in ASP.NET

http://brianrhody.com/articles/JqueryVisualSelectArticle.html

Monday, July 11, 2011

How to solve web service not working in AutoCompleteExtender?


Make sure added [System.Web.Script.Services.ScriptService] into class level of web service


using System;
using System.Collections.Specialized;
using System.Web.Services;

namespace testauto
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class test : System.Web.Services.WebService
    {
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetCompletionList(string prefixText, int count)
        {
            StringCollection names = new StringCollection();
            names.Add("a");
            names.Add("ab");
            names.Add("abc");
            names.Add("b");
            names.Add("bb");
            String[] namesarray = new String[names.Count];
            names.CopyTo(namesarray, 0);
            return namesarray;

        }
    }
}


        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" ServicePath="~/test.asmx" MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20">
        </asp:AutoCompleteExtender>


Tricks I Learned At Apple: Steve Jobs Load Testing

http://blog.joemoreno.com/2011/06/tricks-i-learned-at-apple-steve-jobs.html

Objective-C and Lua to become language of the year



http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Friday, July 8, 2011

How to show busy cursor while loading a page in ASP.NET?


Put loading information into one div, and main contain to another div. Then use jQuery ready function to show main content and hide busy cursor
        $(document).ready(function () {
            $('#loadinginfo').hide();
            $('#mainContain').show();
        });

How to centralize content in div by CSS?


<div style="width: 50%; margin: 0 auto;">Hello</div>
OR
<div style="text-align: center">
    <div style=
"width: 50%; margin: 0 auto; text-align: left">Hello</div>
</div>