Mobile Content

Thursday, October 11, 2012

Insert and Retrieve Image from Database (Sql Server) in .net

In this Example I will show you how to insert and fetch Image Directly from Database.

Step 1. First We will create Table.




Step 2.
Now code to insert image in Database
SaveImage.aspx

Design.

<form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server"
        Text="Button" onclick="Button1_Click" />
</form>


Code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class saveimageinbinary : System.Web.UI.Page
{
    SqlConnection conn;
    string s = ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString.ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new SqlConnection(s);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        StartUpLoad();
    }
    private void StartUpLoad()
    {

        //get the image file that was posted (binary format)

        byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
        HttpPostedFile Image = FileUpload1.PostedFile;
        Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
        int length = theImage.Length; //get the length of the image
        string fileName = FileUpload1.FileName.ToString(); //get the file name of the posted image
        string type = FileUpload1.PostedFile.ContentType; //get the type of the posted image
        int size = FileUpload1.PostedFile.ContentLength; //get the size in bytes that
        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
        {
            //Call the method to execute Insertion of data to the Database
            ExecuteInsert(theImage, fileName, length);
            Response.Write("Save Successfully!");
        }
    }

    private void ExecuteInsert(byte[] Image, string Name, int length)
    {
        
        string sql = "INSERT INTO TblImages (Image, ImageName) VALUES "
       + " (@img,@imgname)";

       // SqlCommand cmd = new SqlCommand(sql,conn);

       // conn.Open();
       //// cmd.ExecuteNonQuery();
       
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[4];

            param[0] = new SqlParameter("@img", SqlDbType.Image, length);

            param[1] = new SqlParameter("@type", SqlDbType.NVarChar, 50);
            param[2] = new SqlParameter("@imgsize", SqlDbType.BigInt, 9999);
            param[3] = new SqlParameter("@imgname", SqlDbType.NVarChar, 50);

            param[0].Value = Image;

            param[1].Value = Type;
            param[2].Value = Size;
            param[3].Value = Name;

            for (int i = 0; i < param.Length; i++)

            {
                cmd.Parameters.Add(param[i]);
            }

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
        
            conn.Close();
        }
    }
}

Step 3
Fetch Image from Database.
Here I am using Handler.ashx page to retrieve image.
ShowImage.aspx


Design.


 <div>
 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"             onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList><br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
</div>

Code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class showbinaryimage : System.Web.UI.Page
{
    SqlConnection connection;
    string s = ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString.ToString();
    private void BindFileNames()
    {

        DataTable dt = new DataTable();
      //  SqlConnection connection = new SqlConnection(GetConnectionString());

        try
        {
            connection.Open();
            string sqlStatement = "SELECT * FROM TblImages";
            SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);

            sqlDa.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                DropDownList1.DataSource = dt;
                DropDownList1.DataTextField = "ImageName"; // the items to be displayed in the list items
                DropDownList1.DataValueField = "Id"; // the id of the items displayed
                DropDownList1.DataBind();
            }
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Fetch Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            connection.Close();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindFileNames();
            connection = new SqlConnection(s);
        }
    }
    public string GetConnectionString()
    {
        //sets the connection string from your web config file "ConnString" is the name of your Connection String
        return System.Configuration.ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString;
    }
    private void GetImageInfo(string id)
    {
        
        string sql = "SELECT * FROM TblImages WHERE Id = @id";

        SqlCommand cmd = new SqlCommand(sql, connection);
        cmd.Parameters.AddWithValue("@id", id);
        connection.Open();

        SqlDataReader reader = cmd.ExecuteReader();
        reader.Read();

        //Get Image Information
        Label1.Text = reader["ImageName"].ToString();
        reader.Close();
        connection.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            //Set the ImageUrl to the path of the handler with the querystring value
            Image1.ImageUrl = "Handler.ashx?id=" + DropDownList1.SelectedItem.Value;
            //call the method to get the image information and display it in Label Control
            GetImageInfo(DropDownList1.SelectedItem.Value);
        }
    }
   
}


Handler.ashx



<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public class Handler : IHttpHandler {

    public string GetConnectionString()
    {
        //sets the connection string from your web config file "ConnString" is the name of your Connection String
        return System.Configuration.ConfigurationManager.ConnectionStrings["imageconverter"].ConnectionString;
    }
     public void ProcessRequest(HttpContext context)
    {
        string id = context.Request.QueryString["id"]; //get the querystring value that was pass on the ImageURL (see GridView MarkUp in Page1.aspx)

        if (id != null)
        {
           
            MemoryStream memoryStream = new MemoryStream();
            SqlConnection connection = new SqlConnection(GetConnectionString());
            string sql = "SELECT * FROM TblImages WHERE Id = @id";
       
            SqlCommand cmd = new SqlCommand(sql, connection);
            cmd.Parameters.AddWithValue("@id", id);
            connection.Open();

            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();

            //Get Image Data
            byte[] file = (byte[])reader["Image"];

            reader.Close();
            connection.Close();
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
            context.Response.BinaryWrite(file);
            memoryStream.Dispose();

        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

Wednesday, September 5, 2012

Storing Object in ViewState Example

In this Example i am using ViewState and HashTable to store value of textbox.

HashTable class is a serializable, it can be stored in view state without a hitch.

All the control information for the page are store in hashtable and then add the hashtable to the viewstate for the page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class viewstate : System.Web.UI.Page
{
    Hashtable texttosave = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        savealltext(form1.Controls,true);
        ViewState["controltext"] = texttosave;
    }
    private void savealltext(ControlCollection controls,bool savenested)
    {
        foreach (Control control in controls)
        {
            if (control is TextBox)
            {
                texttosave.Add(control.ID, ((TextBox)control).Text);
            }
            if ((control.Controls != null) && savenested)
            {
                savealltext(control.Controls, true);
            }
        }
    }
    protected void btndisplay_Click(object sender, EventArgs e)
    {
        if (ViewState["controltext"] != null)
        {
            Hashtable savedtext = (Hashtable)ViewState["controltext"];
            Label1.Text = "";
            foreach (DictionaryEntry item in savedtext)
            { 
            Label1.Text += (string)item.Key+"="+(string)item.Value+"<br/>";
            }
        }
    }
}
output

Friday, August 17, 2012

Merge Split file in Asp.net

In this example i am showing how to merge split file 

To view Example of Split file Click: Split File Example
in .aspx page
 <asp:Button ID="btnmerge" runat="server" Text="merge" onclick=" btnmerge _Click" /> 
in .cs page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void 
btnmerge_Click(object sender, EventArgs e)
    {

    string[] tmpfiles = Directory.GetFiles(Server.MapPath("file/"), "*.tmp");
                FileStream outPutFile = null;
                string PrevFileName = "";
                foreach (string tempFile in tmpfiles)
                {
                    string fileName = Path.GetFileNameWithoutExtension(tempFile);
                    string ex = Session["extension"].ToString();
                    string baseFileName = fileName.Substring(0, fileName.IndexOf(Convert.ToChar(".")));
                    string extension = Path.GetExtension(ex);
                    if (!PrevFileName.Equals(baseFileName))
                    {
                        if (outPutFile != null)
                        {
                            outPutFile.Flush();
                            outPutFile.Close();
                        }
                        outPutFile = new FileStream(Server.MapPath("merge") + "\\" + baseFileName + extension, FileMode.OpenOrCreate, FileAccess.Write);
                    }
                    int bytesRead = 0;
                    byte[] buffer = new byte[1024];
                    FileStream inputTempFile = new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.Read);
                    while ((bytesRead = inputTempFile.Read(buffer, 0, 1024)) > 0)
                        outPutFile.Write(buffer, 0, bytesRead);
                    inputTempFile.Close();
                    File.Delete(tempFile);
                    PrevFileName = baseFileName;
                }
                outPutFile.Close();
                Response.Write( "Files have been merged and saved at location");
           
    }
output

Thursday, August 2, 2012

Insert/Show Record Using Client Callbacks in asp.net

Client callbacks : Rather than posting back the entire page, your custom control can send a request to the server to get just the additional information it needs.

Example:                                                        On Click of Button Insert Record in Database with text value.

 in .aspx page                                                             <script type="text/javascript">
        function ss() {
            var va = document.forms[0].Text1.value;
            UseCallback(va, "");
      
    
        }
        function show(Text1, context) {
            alert(Text1);
      
        }
    </script> 
      <asp:Panel ID="Panel2" runat="server">
      <input id="Text1" type="text" runat="server" />
      <input id="Button1" type="button" value="button" onclick="ss()"/>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <Triggers>
      <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
     </Triggers>
     <ContentTemplate>
     <asp:Timer ID="Timer1" runat="server" Interval="1000">
     </asp:Timer>
     <asp:DropDownList ID="DropDownList1" runat="server">
     </asp:DropDownList>
     </ContentTemplate>
     </asp:UpdatePanel>
    </asp:Panel>

   in .cs page                              
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
  
 public partial class _Default: System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
    SqlConnection con = null;
    SqlCommand cmd,cmd1 = null;
    DataSet ds = null;
    SqlDataAdapter da = null;
    private string aa = null;
  protected void Page_Load(object sender, EventArgs e)
    {
        string cref = Page.ClientScript.GetCallbackEventReference(this, "arg", "show", "context");
        string cscript = "function UseCallback(arg,context)" +
            "{" + cref + ";" + "}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cscript, true);



 cmd1 = new SqlCommand("select Message from ChatDb", con);
      da = new SqlDataAdapter(cmd1);
      ds = new DataSet();
      da.Fill(ds);
      if (ds.Tables[0].Rows.Count > 0)
      {
        
          DropDownList1.DataSource = ds.Tables[0];
          DropDownList1.DataTextField = "Message";
          DropDownList1.DataBind();
      }
    } 
  public string GetCallbackResult()
    {
        return aa;
    }
    public void RaiseCallbackEvent(string eventArgument)
    {

 cmd = new SqlCommand("insert into ChatDb values('" + eventArgument + "')", con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();


        aa = eventArgument;
    } 
}
OutPut

 

Saturday, July 14, 2012

Piano in Asp.net

In this blog I am showing the example of Making piano.
"Built and play piano using keyboard and mouse"


We can play piano only in client side. On server side this code will not be helpful.
Because i am using "winmm.dll" file for making sound which is located in client computer.


The script will check the keypress event by knowing their ASCII value.
in .aspx

<head runat="server">
    <title></title>
    <script type="text/javascript">


        document.onkeyup = KeyCheck;


        function KeyCheck(e) {
            var KeyID = (window.event) ? event.keyCode : e.keyCode;
            {
                __doPostBack('__Page', KeyID);
                
            }
        }


    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 200px; vertical-align: top; background-color:Yellow;" align="center">
        <table>
            <tr>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button1" runat="server" Text="A" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top" style="width:41px">
                    <asp:Button ID="Button2" runat="server" Text="S" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button3" runat="server" Text="D" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button4" runat="server" Text="F" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button5" runat="server" Text="G" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button6" runat="server" Text="H" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button7" runat="server" Text="J" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                 <td valign="top"  style="width:41px">
                    <asp:Button ID="Button8" runat="server" Text="K" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button9" runat="server" Text="L" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
                 <td valign="top"  style="width:41px">
                    <asp:Button ID="Button10" runat="server" Text=";" BackColor="Black" BorderColor="white"
                        BorderStyle="Solid" BorderWidth="1px" Height="139px" Style="margin-bottom: 0px"
                        ForeColor="White" Width="41px" />&nbsp;
                </td>
                <td valign="top"  style="width:41px">
                    <asp:Button ID="Button11" runat="server" Text="'" BackColor="White" BorderColor="Black"
                        BorderStyle="Solid" BorderWidth="1px" Height="192px" Width="41px" />
                    &nbsp;
                </td>
            </tr>
        </table>
    </div>
    <div style=" vertical-align: top;" align="center">
        <table>
            <tr>
                <td valign="top"  style="width:41px" align="center">
                    <asp:Image ID="Image1" runat="server" Width="20px" Height="20px"/> 
                  
                </td>
                <td valign="top" style="width:41px"  align="center">
                 <asp:Image ID="Image2" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                   <asp:Image ID="Image3" runat="server" Width="20px" Height="20px" /> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                    <asp:Image ID="Image4" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image5" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                   <asp:Image ID="Image6" runat="server" Width="20px" Height="20px"/> 
                </td>
                <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image7" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image8" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image9" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image10" runat="server" Width="20px" Height="20px"/> 
                </td>
                 <td valign="top"  style="width:41px"  align="center">
                  <asp:Image ID="Image11" runat="server" Width="20px" Height="20px"/> 
                </td>
            </tr>
        </table>
    </div>


    <%--<div style=" vertical-align: top;">
       
                    <asp:Image ID="Image12" runat="server" Width="20px" Height="20px" ImageUrl="~/up_arrow.png" style="padding-left:420px"/> 
                  
              
    </div>--%>
    <div align="center">
       <font size="5px" style="font-family:Garamond;" color="red"> Press the no given on piano, to listen sound.</font>
    </div>
    </form>
</body>

Now Code


in .vb page



Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic.Devices
Imports Microsoft.VisualBasic




Partial Class piano1
    Inherits System.Web.UI.Page
    <DllImport("winmm.dll", EntryPoint:="mciSendStringA")> _
    Private Shared Function mciSendString(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    End Function
    Dim computer As New Computer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        computer.Audio.Stop()
        visi()
        borderwid()
        Page.ClientScript.GetPostBackEventReference(Me, "")
        Dim eventArgs As String = Request("__EVENTARGUMENT")
        If eventArgs <> "" Then
            If eventArgs = "65" Then


                playsound1()


            ElseIf eventArgs = "83" Then
                playsound2()


            ElseIf eventArgs = "68" Then
                playsound3()
            ElseIf eventArgs = "70" Then
                playsound4()
            ElseIf eventArgs = "71" Then
                playsound5()
            ElseIf eventArgs = "72" Then
                playsound6()
            ElseIf eventArgs = "74" Then
                playsound7()
            ElseIf eventArgs = "75" Then
                playsound8()
            ElseIf eventArgs = "76" Then
                playsound9()
            ElseIf eventArgs = "59" Or eventArgs = "186" Then
                playsound10()
            ElseIf eventArgs = "222" Then
                playsound11()
            End If
        End If


    End Sub
    Public Sub visi()
        Image1.Visible = False
        Image2.Visible = False
        Image3.Visible = False
        Image4.Visible = False
        Image5.Visible = False
        Image6.Visible = False
        Image7.Visible = False
        Image8.Visible = False
        Image9.Visible = False
        Image10.Visible = False
        Image11.Visible = False
    End Sub
    Public Sub borderwid()


        Button1.BorderWidth = "1"
        Button2.BorderWidth = "1"
        Button3.BorderWidth = "1"
        Button4.BorderWidth = "1"
        Button5.BorderWidth = "1"
        Button6.BorderWidth = "1"
        Button7.BorderWidth = "1"
        Button8.BorderWidth = "1"
        Button9.BorderWidth = "1"
        Button10.BorderWidth = "1"
        Button11.BorderWidth = "1"
    End Sub
    Public Sub playsound1()
        computer.Audio.Play(Server.MapPath("piano/s1.wav"), AudioPlayMode.Background)
        Image1.Visible = True
        Image1.ImageUrl = "~/image/up_arrow.png"
        Button1.BorderWidth = "3"
    End Sub
    Public Sub playsound2()
        computer.Audio.Play(Server.MapPath("piano/s2.wav"), AudioPlayMode.Background)
        Image2.Visible = True
        Image2.ImageUrl = "~/image/up_arrow.png"
        Button2.BorderWidth = "3"
    End Sub
    Public Sub playsound3()
        Image3.Visible = True
        Image3.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s3.wav"), AudioPlayMode.Background)
        Button3.BorderWidth = "3"
    End Sub
    Public Sub playsound4()
        Image4.Visible = True
        Image4.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s4.wav"), AudioPlayMode.Background)
        Button4.BorderWidth = "3"
    End Sub
    Public Sub playsound5()
        Image5.Visible = True
        Image5.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s5.wav"), AudioPlayMode.Background)
        Button5.BorderWidth = "3"
    End Sub
    Public Sub playsound6()
        Image6.Visible = True
        Image6.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s6.wav"), AudioPlayMode.Background)
        Button6.BorderWidth = "3"
    End Sub
    Public Sub playsound7()
        Image7.Visible = True
        Image7.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s7.wav"), AudioPlayMode.Background)
        Button7.BorderWidth = "3"
    End Sub


    Public Sub playsound8()
        Image8.Visible = True
        Image8.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s8.wav"), AudioPlayMode.Background)
        Button8.BorderWidth = "3"
    End Sub


    Public Sub playsound9()


        Image9.Visible = True
        Image9.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s9.wav"), AudioPlayMode.Background)
        Button9.BorderWidth = "3"
    End Sub
    Public Sub playsound10()
        Image10.Visible = True
        Image10.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s10.wav"), AudioPlayMode.Background)
        Button10.BorderWidth = "3"
    End Sub
    Public Sub playsound11()
        Image11.Visible = True
        Image11.ImageUrl = "~/image/up_arrow.png"
        computer.Audio.Play(Server.MapPath("piano/s11.wav"), AudioPlayMode.Background)
        Button11.BorderWidth = "3"
    End Sub




    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        visi()
        borderwid()
         playsound1()
    End Sub


    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        visi()
        borderwid()
        playsound2()
    End Sub


    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        visi()
        borderwid()
        playsound3()
    End Sub


    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        visi()
        borderwid()
        playsound4()
    End Sub


    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
        visi()
        borderwid()
        playsound5()
    End Sub


    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
        visi()
        borderwid()
        playsound6()
    End Sub


    Protected Sub Button8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button8.Click
        visi()
        borderwid()
        playsound8()
    End Sub


    Protected Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button9.Click
        visi()
        borderwid()
        playsound9()
    End Sub


    Protected Sub Button10_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button10.Click
        visi()
        borderwid()
        playsound10()
    End Sub


    Protected Sub Button11_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button11.Click
        visi()
        borderwid()
        playsound11()
    End Sub


    Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
        visi()
        borderwid()
        playsound7()
    End Sub
End Class

Enjoy Piano