July 25, 2013

Code Example for Wizard Server Control in ASP.NET

Below is the code example for wizard control in ASP.NET

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

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

    <form id="form1" runat="server">
    <asp:wizard ID="Wizard1" runat="server" DisplayCancelButton="True"> 
     <WizardSteps> <asp:WizardStep ID="WizardStep1" title="Personal Info"  runat="server">
             Name <asp:TextBox ID="txtName" runat="server"/><br />
             Phone  <asp:TextBox ID="txtPhone" runat="server"/>

     <asp:WizardStep ID="WizardStep2" title="Company Info"     runat="server">
              Company Name <asp:TextBox ID="txtCompName" runat="server"/><br />
              Company Phone <asp:TextBox ID="txtCompPhone" runat="server" />
         <asp:WizardStep runat="server" StepType="Complete">

         <asp:Label runat="server" Text="" id="lblPersonal"></asp:Label>
         <asp:Label runat="server" Text="" id="lblComp"></asp:Label> </asp:WizardStep>
     </WizardSteps> </asp:wizard>

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

public partial class ExWizard : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        lblPersonal.Text = txtName.Text + "  " + txtPhone.Text;
        lblComp.Text = txtCompName.Text + "  " + txtCompPhone.Text;

July 15, 2013

Parameters in C# code example

Set of arguments that must be provided for that method are parameters 

  Different ways of passing parameters in C# 
               Pass by Value (Value Of Parameter Passed)
      Pass by ref  (Memory Location or Ref of Parameter is passed)
      Out (  variable is assigned a value before returning from a method)
      Params (  any number of parameters of a particular type)

See the below code example 

using System;
using System.Text;
class Test
    static void DisplayUsingValue(int p) { ++p; }
    static void DisplayUsingRef(ref int p) { ++p; }
    static void DisplayUsingOut(int p , out int y)

    static int Add(params int[] iarr)
        int sum = 0;
        foreach (int i in iarr)
            sum += i;
        return sum;

    static void Main()
        int x = 8;
        DisplayUsingValue(x); // make a copy of the value-type x
        Console.WriteLine("output From Pass By Value Method Demo  ");
        Console.WriteLine(x); // x will still be 8

        DisplayUsingRef(ref x);
        Console.WriteLine("output From Pass By Ref Method Demo  ");

        int a;
        DisplayUsingOut(x, out a);
        Console.WriteLine("output From out parameter  Demo  ");

        int result = Add(1, 2,7);
        Console.WriteLine("output From params[]  Demo  ");


And See the output 
"output From Pass By Value Method Demo
output From Pass By Ref Method Demo
output From out parameter  Demo 
output From params[]  Demo