-->

Monday, September 2, 2013

Dynamically Enable or Disable ASP.NET Controls

If your controls are enable then you take some action onto the controls such as checked or unchecked CheckBox and If they are disable then you don't take some action onto the controls.
In previous example we saw checked property of checkbox control .

Example of Dynamically Enable or Disable ASP.NET Controls


<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Button2_Click(object sender, EventArgs e)
    {
        Button1.Enabled = true;
        CheckBox1.Enabled = true;
        RadioButton1.Enabled = true;
        TextBox1.Enabled = true;
     
     

    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        Button1.Enabled = false;
        CheckBox1.Enabled = false;
        RadioButton1.Enabled = false;
        TextBox1.Enabled = false;

    }
</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="Button Control" />

        <br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox Controls" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server" Width="164px">TextBox Control</asp:TextBox>
        <br />
        <br />
        <asp:RadioButton ID="RadioButton1" runat="server" Text="Radio Button Control" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Controls Enable" />
&nbsp;
        <asp:Button ID="Button3" runat="server" Text="Controls Disable" OnClick="Button3_Click" />

    </div>
    </form>
</body>
</html>

Output
Dynamically disable controls Dynamically Enable controls


How to use Checked property of CheckBox Control

Checked property is shows that your checkbox is either checked or not .Take a one example for showing image when your checkbox is checked. algorithm of the example are:
-->Drop one CheckBox control to Webpage
-->Set AutoPostBack property is true. Because when your CheckBox is checked then your page request send to the server . After server response your business logic event handler should executed.

Example of Showing Image when your CheckBox is checked.


<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
        {
            Image1.Visible = true;
        }
        else
        {
            Image1.Visible = false;
        }
     
     
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Checked Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="Show Image" OnCheckedChanged="CheckBox1_CheckedChanged" />
        <br />
        <asp:Image ID="Image1" runat="server" Height="161px" ImageUrl="~/download.jpg" Visible="False" Width="175px" />
    </div>
    </form>
</body>
</html>

Output
How to use Checked property of CheckBox Control

Sunday, September 1, 2013

How to get Multiple selected listbox item in ASP.NET


<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (ListItem li in ListBox1.Items)
        {
            if (li .Selected )
            {
                result.Text += li.Text + "<br/>";
                 
            }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox SelectionMode ="Multiple" ID="ListBox1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
            <asp:ListItem>Your first item</asp:ListItem>
            <asp:ListItem>Your Second Item</asp:ListItem>
            <asp:ListItem>Your Third item</asp:ListItem>
        </asp:ListBox>
        <br />
        <br />
        <asp:Label ID="result" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

Output
How to get Multiple selected listbox item in ASP.NET

Online camera shopping cart project in ASP.NET

Introduction

Its a shopping cart project which is used over the network. Present time online shopping companies get benefits from online selling because they getting lots of money compare to manual marketing. The scene of the project is making online application which is used for online shopping. Basically this application is designed for camera only also its a demo application.





Application of the project

  • Gets some extra cash from online selling
  • Application is designed for Institutional purpose
Features of the project
  • Add new category and sub-category of the camera
  • User registration page
  • Online cashing
  • Searching facility
  • User session
  • Add to cart facility
  • Admin panel
  • Customer panel

Hardware and software requirements of the project

  • Visual studio 2010
  • SQL-SERVER 2008

How to run your project

  • Open your project in VS2010
  • Run your home page
  • First register into this site
  • After that click on any camera which you want to purchase
  • Add quantity and add item to the cart
  • In admin panel first check your admin password in server explorer 
  • Add new camera detail after login into Admin panel


If you want to purchase this please contact me on :  narenkumar851@gmail.com

Silverlight Tutorial : Create Simple Silverlight Application

The easiest way to start Silverlight is to create an ordinary website with HTML pages and no server-side code . Here's how
1. Select File--> New-->Project in visual studio , choose the visual c# group of project types, and select the Silverlight Application template . As usual , you need to pick a project name and a location on your hard drive before clicking OK to create the project.

Silverlight Application template

2. At this point , visual studio will prompt you to choose whether you want to create full -fledged ASP.NET website that can run server-side code along with your silverlight . In visual studio , uncheck the "Host the Silverlight application in a website" option to keep things simple.
 uncheck the "Host the Silverlight application in a website

3. Click OK to continue and create the project.
Every Silverlight project start with a small set of essential files. All the files that end with the extension .xaml use a flexible markup standard called XAML. All the files that end with the extension .cs hold the C# source code that powers your application.
Every Silverlight project start with a small set of essential files
App.xaml and App.xaml.cs files configure your Silverlight application they allow you to resources that will be made available to all the pages in your application, and they allow you to react to application events such as startup, shutdown and error conditions.

MainPage.xaml files defines the user interface(the collection of controls, images, and text) that will be shown for your first page. Technically , Silverlight pages are user controls-custom classes that drive from UserControl. A Silverlight application can contain as many pages as you need - to add more , simply choose project-->Add new item, pick the silverlight User Control template.

Example of Create Simple "Hello World Application" in  Silverlight 

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">



    <Grid x:Name="LayoutRoot" Background="Black">
        <TextBox Text=" Hello World!" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>



    </Grid>
</UserControl>


Output
 Create Simple Silverlight Application

Saturday, August 31, 2013

How to Use Calendar Control: WPF

To select a date in our client application, enter the date into a textbox and then convert it to the particular class i.e. DateTime. What, if there is an in-built control to select a date, month and a year also. Calendar control is used to do these task and look like the following:

Display Modes of Calendar Control in WPF

The image shows three display modes of this calendar control i.e. month, year and decade respectively. By default it is Month view (the first view). User can switch the view to click on month and then year and so on. It have some commonly used properties which are:

DisplayDate: To specify the displayed date in the calendar control. Assign the date in the system date format.

SelectedDate: change the currently selected date. Used as the display date. If the control shows the old date we can change it to current using following code:
<Calendar SelectedDate="{x:Static sys:DateTime.Now}"/>

SelectionMode: it provides multiple modes for selection like “MultipleRange”. We can select a range of dates by using this property.

BlackoutDates: this control provides a feature of black out some dates means user cannot select some of the date blocked by system.
<Calendar>
<Calendar.BlackoutDates>
<CalendarDateRange Start="08.04.2013" End="08.04.2013"/>
<CalendarDateRange Start="08.16.2013" End="08.24.2013"/>
</Calendar.BlackoutDates>
</Calendar>
It will cross all the dates specified in the above range as shown in the following image:

Blackout Dates in Calendar Control: WPF

DisplayMode: to change the display modes i.e. year, month and decade as in our first diagram.

Like other controls it also have many events like selectedDatesChanged, displayDateChanged, displayModeChanged and etc. We can specify the actions to be performed at the particular event. Calendar control can be customizable as per the requirement of the user like background and foreground.

See also: Button Control

Ways to Use Button Control: WPF

Button, a simple and small name to listen in all the programming languages. All the windows, forms, dialog boxes and even user controls mostly use this button to be performed some action. Open, close, submitting a form and whatever to do can also be performed by button.

Button control is of content control type, means it have a content property to be assigned by us. The content may be a string or anything that can be used under the conditions.

<Button Name=”loginButton” Content=”Click to Login”></Button>

The above button will look like a standard button control and saying the user to click if he/she want to login. Actually, it only have its content property, doesn’t have defined any action to be performed when user will click. So click event have to be defined to perform an action when user click on it.



<Button Name="loginButton" Content="Click to Login" Click="loginButton_Click"></Button>

In the code behind file the click event is generated like the following code in C# language
private void loginButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("You are logged in");
}
The message box is not pre-defined. When user click on the button it will show the above message each time. We can bind our button to the commands defined in a class to be performed the same action as in click event. The following code is used to bind a button to a command.

<Button Name="loginButton" Content="Click to Login" Command="{Binding ClickCommand}"></Button>

The command can be simply defined as the below code in C# language:
public ICommand ClickCommand
{
get
{
return showDetailCommand;
}
}
ICommand is the interface that is used for this command binding. We will learn it later. We can use a button as per our requirements using its properties.

© Copyright 2013 Computer Programming | All Right Reserved