-->

Monday, February 3, 2014

Client and Server HTML Controls in ASP.NET

There are 2 ways in which to figure with the hypertext mark-up language controls; initial, by exploitation them as hypertext mark-up language client controls and handling their respective events events at the client-side, and second, by running these controls at the server-side and handling the events of the hypertext mark-up language controls within the code-behind file exploitation any programming language supported by .NET Framework, like C# or Visual Basic. during this former case, you want to use a scripting language, like JavaScript. for handling events and performing validations. exploitation hypertext mark-up language controls as client controls is additionally the default style of hypertext mark-up language controls. However, html controls support limited events that may be handled on the server, for instance, the events like onblur, onfocus, and onhelp are available at the client-side however not at the server-side.

HTML controls are present within the under or Visual Studio beneath a tab named hypertext mark-up language. you'll handle the events in hypertext mark-up language presentation code using a scripting language, like JavaScript. an hypertext mark-up language control is became an hypertext mark-up language server management by adding the runat="server" attribute to that. depending on the necessities, an hypertext mark-up language control is used as client-side control or server-side management. as an example, an hypertext mark-up language control is used as a client-side control once you need to handle the events of hypertext mark-up language controls victimization client resources. On the opposite hand, if you wish the controls to show information from server and separate the hypertext mark-up language presentation code from application logic code, then you ought to use the hypertext mark-up language control as a server side control.
By default, HTML control is a client-side control and can be used for scripting in the Web page only. ASP.NET IDE provides a unique identity to each control that you can use to refer the control in your script code. The control's ID is available with the id property in the properties window. You can change the ID of any control as per your requirement. Since ID refer to the unique identity of every control, every control must have a separate ID.

Even if you turn the HTML control into server -side control, it will continue to use the status default ID that is provided to it by ASP.NET IDE . Naming of HTML controls is different from that of ASP.NET controls. For example, the default ID of a TextBox control in ASP.NET is TextBox1, whereas for an HTML control, it would be Text1.

HTML server controls have no AutoPostBack property , which means that events have to wait to be raised by the user. Suppose you create a Submit button and add the runat="server" attribute to it. Now, the page is not processed unless the Submit button is clicked.

Array Function in PHP Programming

Array functions: - PHP provide various functions to perform different operations on array like searching, sorting, merging, splitting etc.  Here we have some important php functions which used to perform major operations on PHP array.

sort():- This function is used to sort the array according to its value. For example

$names=array (‘a’,’c’’b’);
Sort ($names);
After execute this funcitn the array will be
$names=array (‘a’,’b’’c’);
8/*

sizeof():- This function is used to determine size of array. This function return number of elements available in that array. For example

$arary=array(1,2,3,4);
$s=sizeof($arrray);
Here in $s we have 4. This is size of this array.

array_merge():- This function is used to merge two array. For example

$first = array ('hello', 'world');    
$second = array ('exit', ‘here’);    
$merged = array_merge ($first, $second);
After execute this code the $merged array will be
// $merged = array ('hello', 'world', 'exit', 'here')

•     array_reverse() :- This function is used to reverse the array elements. For example

$array=array (1,2,3,4);
array_reverse($array);
after execute this code the array will be
$array=array (4,3,2,1);

Sunday, February 2, 2014

Types of Array in PHP Programming


Types of array: - In real world we have two types of array. These are following :-

Single dimensional array: -
                                             In this array data items stored in only in one dimension.
Like $word [1] =”hello” which means the array $word stores the items in one dimension such as $word [1] $word [2] $word [3] $word [5] etc. The arrays which we have discussed in previous topics all are single dimensional array.

Multidimensional Arrays: -
                                             If an array is able to store the items at more than one dimensional is called multidimensional array. Multidimensional array comes in picture where we need to store different association with single variable. For example if we want to make a matrix of size 2x2 the array representation will be.

$mat[ 0] [0]=2
$mat[ 0] [1]=4
$mat[ 1] [0]=7
$mat[ 1] [1]=6

Here the array $mat use two direction first is for row and second for column. So this is called two dimensional array. We can create any dimensional array in PHP . Such that

$threeDarray[ ][ ][ ]
$fourDarray[ ][ ][ ][ ]
$fifthDarray[ ][ ][ ][ ][ ]
$nDarray [ ][ ][ ][ ][ ][ ][ ]……..[ ][ ]

Concept of multidimensional array can be understood with the help of example:-
$shop= array(‘fruit’ =>
array(‘red’ => ‘apple’,
‘orange’ => ‘orange’,
‘yellow’ => ‘banana’,
‘green’ => ‘pear’),
‘flower’ =>
array(‘red’ => ‘rose’,
‘yellow’ => ‘sunflower’,
‘purple’ => ‘iris’));

It is simply an array with two values stored in association with keys. Each of these values is
an array itself. After we have made the array, we can reference it like this:-
if we want to check which  fruit of color red then we use

$shop [fruit][red]; this statement return the value “apple”.

How to use Substitution Control in ASP.NET

The substitution control is used to specify a section on an output-cached Web page where you want to substitute the dynamic content for the control. This control provides a simplified solution to partial page caching for pages where the majority of the content is cached. You can output  cache the entire page, and then use the Substitution control to specify the sections of the page that are exempted from caching.

Public Properties of the Substitution class

MethodName : Callback method to call up when the Substitution control executes.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="substitution.aspx.cs" Inherits="substitution" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script runat="server">  
    static string dotprogramming(HttpContext context) {

        string name = DateTime.Now.ToString();
        return name;
          
    }  
</script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Page Cached DateTime<br />
&nbsp; <%= DateTime.Now.ToString() %> 
        <br />
        Current Time without cache<br />
&nbsp;<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
        <asp:Substitution ID="Substitution1" runat="server" 
            MethodName="dotprogramming" />
    </div>
    </form>
</body>
</html>

In this example page cached for 300 seconds using OutputCache directive , But you can refresh content using Substitution control.
Code Generate the following Output
How to use Substitution Control in ASP.NET

How to use Substitution Control in ASP.NET

How to use HiddenField Control in ASP.NET

The HiddenField control is used to store a value that needs to persist across posts to the server. Normally, view-state, session-state, and cookies are used to maintain the state of the Web form page. In case, if these methods are disabled or are not available, you can use the HiddenField  control to store state values. Here is the class hierarchy for the HiddenField class :

System.Object
   System.Web.UI.Control
      System.Web.UI.WebControls.HiddenField

Public Properties of the HiddenField Class

EnableTheming : Check, Whether theme is apply or not onto this control.
SkinID : Retrieve specific style from skin file and apply to the control.
Value : value of the HiddenField

Lets take an simple example 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>Hidden Field Contro Example</h2>
        <p>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                Text="Click Me!" />
        </p>
    </div>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <br />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>

// Code Behind Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HiddenField1.Value = "Welcome to dotprogramming";

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = HiddenField1.Value;

    }
}
Code Generate the following output
How to use HiddenField Control in ASP.NET

How to use PlaceHolder Control in ASP.NET

The PlaceHolder Control
The PlaceHolder control is used as a container to store server controls that are added to the Web page at runtime. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page.

Example of PlaceHolder control

 
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox text = new TextBox();
        text.Text = "This is the runtime textbox";
        text.Style["width"] = "300px";
        PlaceHolder1.Controls.Add(text);       
           
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Click to add TextBox" OnClick="Button1_Click" />
        <br />
        <br />
        <br/>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
    </div>
    </form>
</body>
</html>
Output
Add Textbox on runtime

Saturday, February 1, 2014

Dynamic and Static Memory Allocation in C Programming


Memory is allocated to the respective data variables (of any type of data structure) in two manners that are dynamic and static.
The memory if it allocated to the variables declared, during the compilation process is called as a static memory allocation whereas the allocated to the variables, during the execution of the program is called as dynamic memory allocation.
Once the memory is allocated statically it cannot be altered during the execution of the program. So the programmer may need the memory that is to be allocated as per the request during the program execution. So there comes dynamic memory allocation. Dynamic memory allocation is possible only when pointers are used. A pointer variable is used to store the base address of dynamically allocated memory.

      void main()
          {
            int array[20];
            . . . . .
         }

In this case when the program is compiled, main memory is allocated to the array. So it is static memory allocation. Once the memory is allocated to “array”, it cannot be altered during execution. Here if the programmer wishes to store more numbers of elements in the array it is not possible. He can change the size of array, only before compilation. Now if he is decides the size of array as 50 and if he is stored only few elements then there is wastage of main memory. Usually if the elements that are to be stored in an array is not decided before compilation and it is decided during the execution of the program then the static memory allocation has a major drawback.


In the order to overcome the above-mentioned problem now programmer can request the required memory during the execution of program using pointer variable. It is dynamic memory allocation.
For example, consider the following program segment:-
      
void main()
          {
            int *arr, size;
            /* user can get size of the array during execution */
           arr= (int *) malloc (size of (int) * size);
            . . . .
         }

In this case the dynamic memory is allocated by the malloc function during the execution of program and the base is returned is stored in a pointer variable arr. With the help of arr now it is possible to refer as many elements as user wishes during the execution of the program. That is the major concept of dynamic memory allocation.

© Copyright 2013 Computer Programming | All Right Reserved