May 24, 2011

jQuery VS Javascript

It's all about performance and development speed.

-----------
jQuery :
-------------


  1. jQuery is library or you can say that its built on javascript
  2. Jquery is need to be access through jquery patch latest patch is 1.5
  3. Another advantage of jquery is that its less your code rather than using javascript.
  4. In complex situation Jquery will be more helpfull due to less code written and easily manageable
-------------------
JavaScript : 
-------------------



  1. Javascript is client language for which you dont need any requirement.
  2. It is incredibly useful and overused, but that if you really need it, a framework is the way to go.
  3. Javascript is the source, the actual scripts that browser responds to.

Web Site VS Web Application

There is very big difference between Web Site and Web Application, some points are given below, but there is no difference in speed or performance between both of them.............

Web Site

  1. Web Site is just one folder which contains the files and resources
  2. Web Site is open using browser from Visual Studio
Web Application

  1. Web Application creates one solution file which may contain multiple projects in it
  2. If you are working on 3-tier or n-tier application then this type is good
  3. It is easy to maintain, its movable and it contain file in DLL format
  4. All files are compiled in .dll file on time of deployment

Table Like Structure of Div

There is very simple css code to make div which behave like a table but in reality its not a table. It is the composition of CSS on Div to make Div as Table

CODE

<div id="divContainer" style="width:600px; height: 100px">

        <div style="width:50%;height: 100%; float:left;">

                <div style="width:100%; height:25%; display:block; border: 1px solid black; border-bottom:none"></div>

                <div style="width:100%; height:25%; display:block; border: 1px solid black; border-bottom:none"></div>

                <div style="width:100%; height:25%; display:block; border: 1px solid black; border-bottom:none"></div>

                <div style="width:100%; height:25%; display:block; border: 1px solid black"></div>

        </div>

        <div  style="width:50%; height: 100%; float:left;">

                <div id="divWithPadding" style="width:100%; height:50%; display:block; border: 1px solid black; border-bottom:none; border-left:none; padding-top:1px"></div>

                <div style="width:100%; height:25%; display:block; border: 1px solid black; border-bottom:none; border-left:none"></div>

                <div style="width:100%; height:25%; display:block; border: 1px solid black; border-left:none"></div>

        </div>

</div>



Fixed the size of gridview

How can i fixed the size of grid with respect to their hieght and width. Problem occurs on address column when long address placed in it it increase its width and sperad its width from page. Thats why i wants that if address is will increase the width of gridview rather moving forward its terminated line and then placed reamining words in next lines. I fixed the width of gridview and reamins free in auto mode the height of gridview.

There are several ways u can solve that issue by just taking an item template and put your address bounded column in that item template

CODE

<asp:TemplateField HeaderText="Title" SortExpression="Title" ItemStyle-Width=200>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
<HeaderStyle VerticalAlign="Middle" />
<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="200px" /> </asp:TemplateField>

Dynamically change the year of copyright

In footer section i placed image of copyright in which 2011 year is mentioned. But its fixed, when 2012 comes footer reamins to 2011 year of copyright how can i change that year when new comes? i want to create a jQuery code for that purpose which pick the desire year pic according to current year and placed it to the footer section automatically because of this it save alot of time every year when changed.

Code is very simple use below code and makes your images name as 2011.png, 2012.png etc

CODE

<img src="/images/<%= DateTime.Now.Year %>.png" alt="Copyright" />

Asp.Net multiline textBox character counting to custom limit via JavaScript

Here's the code to tells that how can I limit the user to certain characters length using javascript along with asp.net Textbox control

ASPX MARKUP


<div>
    <p>
        Asp.Net TextBox Character Counting using Javascript Limit Characters to 135
    </p>
    <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" onKeyUp="CheckLimit();"></asp:TextBox><asp:RequiredFieldValidator
        ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="txtMessage"
        Display="Dynamic"></asp:RequiredFieldValidator>
    <font size="1">(Maximum characters: 135)<br />
        You have
        <asp:Label ID="lblCountLimit" runat="server" Text="135" ForeColor="Red"></asp:Label>
        characters left.</font>
</div>

JAVASCRIPT CODE

function CheckLimit() {
var textField =
    document.getElementById("<%=txtMessage.ClientID %>");
var labelCount =
    document.getElementById("<%=lblCountLimit.ClientID %>");

   if (textField.value.length > 135) {
       textField.value = textField.value.substring(0, 135);
   } else {
       labelCount.innerHTML = 135 - textField.value.length;
   }
}

Character Counting from Asp.Net Textbox using JavaScript

Many peoples asked on different forums inc that how can we calculate Textbox character onkeyup events using JavaScript. The way is very simple here is short code of that query. I also functionality that if length of character less than or equal to 160 then total no. of sms is 1 and vice versa.
ASPX MARKUP
<div>
    <p>
        Asp.Net TextBox Character Counting using Javascript If > 160 then Show SMS: 02
    </p>
    <asp:TextBox ID="txtMessageText" runat="server" TextMode="MultiLine" onKeyUp="CountCharacter();"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvMessageText" runat="server" ErrorMessage="*" ControlToValidate="txtMessageText"
        Display="Dynamic"></asp:RequiredFieldValidator>
    <font size="1">
        <asp:Label ID="lblCountDown" runat="server"></asp:Label>
    </font>
</div>
JAVASCRIPT CODE
function CountCharacter() {
    var count = 0;
    var mgsLength = 0;

    var textField = 
        document.getElementById("<%=txtMessageText.ClientID %>");
    var labelField = 
        document.getElementById("<%=lblCountDown.ClientID %>");

    var length = textField.value.length;
    var setValue = count + length;

    if (setValue == 0) {
        mgsLength = 0;
        labelField.innerHTML = 
            "Total characters " + setValue + "; No of SMS: " + mgsLength;
    }
    else {
        if (setValue <= 160) {
            mgsLength = 1;
            labelField.innerHTML = 
                 "Total characters " + setValue + "; No of SMS: " + mgsLength;
    }
    else {
        var roundLength = setValue / 160;
        mgsLength = Math.ceil(roundLength);
        labelField.innerHTML = 
                 "Total characters " + setValue + "; No of SMS: " + mgsLength;
    }
  }
}