Search This Blog

Friday, September 27, 2013

Add Video into Webpage



You Can Embed the video in two different ways.


1. From the Tag Video and source
2. From Website The link of Page is given into the iframe.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Video Tag to Embed it. </h1>
      <video width="450" height="300" controls>
  <source src="video.mp4" type="video/mp4">

  Your browser does not support the video tag.
</video>
    </div>
    <div>
    <h1>Concept of Iframe To Embed Directly From Other Websites Like Youtube</h1>
    <iframe width="420" height="315" src="https://www.youtube.com/embed/aFiiX2799Vo" frameborder="0" allowfullscreen></iframe>
    </div>
    </form>
</body>
</html>

For Learn C#.Net, ASP.Net, VB.Net Visit OurWebsite

Saturday, September 7, 2013

Upload/Download File - Asp.net


Click  On Choose File To Upload File .

And

Click On Link Below Download To Download File From Your Project Page.

Create One Directory Name "file" in Your Project
And Create Table That Stores the id And path of your file.

Two source code files
Coding in Aspx Design of webpage and
Code .cs file contains C# coding
Aspx code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Submit" runat="server"
            Text="Submit" onclick="Submit_Click" />
        <br />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField HeaderText="Download">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server"
                            CommandArgument='<%# bind("path") %>' onclick="LinkButton1_Click"
                            Text='<%# bind("path") %>'></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>






aspx.cs 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;
using System.Data.SqlClient;

using System.IO;
public partial class _Default : System.Web.UI.Page
{
 
    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\WebSite1\WebSite14\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            showdata();
        }
    }

    private void showdata()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from tblfile",con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string fname = FileUpload1.FileName;
            string fpath = "~\\file\\"+fname;
            FileUpload1.SaveAs(Server.MapPath(fpath));
            SqlCommand cmd = new SqlCommand("insert into tblfile values('"+fpath+"')",con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string filePath = (sender as LinkButton).CommandArgument;
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();
    }
}
For Learn C#.Net, ASP.Net, VB.Net Visit OurWebsite

Saturday, April 6, 2013

Javascript validations

Email Validation

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var b=emailfilter.test(document.form2.mailid.value);
if(b==false)
{
alert("Please Enter a valid Mail ID");
document.form2.mailid.focus();
return false;
}

Password Validation

var a = document.form.pass.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.pass.focus();
return false;
}
if ((a.length < 6) || (a.length > 20))
{
alert("Your Password must be 6 to 20 Character");
document.form.pass.select();
return false;
}

Mobile number Validation

var a = document.form.phone.value;
if(a=="")
{
alert("please enter your mobile no");
document.form.phone.focus();
return false;
}
if(isNaN(a))
{
alert("Enter the valid Mobile Number(Like : 9999911111)");
document.form.phone.focus();
return false;
}
if((a.length < 10) || (a.length > 10))
{
alert(" Your Mobile Number must be 10 Integers");
document.form.phone.select();
return false;
}

Gender Validation

ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if (ErrorText= "") { form.submit() }
}



Tuesday, April 2, 2013

Create Menu Using Javascript


First Create Six Images.
one.jpg
two.jpg


three.jpg
four.jpg


five.jpg
six.jpg



one and two for HOME
three and four for ABOUT
five and six for CONTACT

<html>
<head><title>Html Javascript </title>
<script = "text\javascript">
function f1()
{
img1.src="two.jpg";
}
function f2()
{
img1.src="one.jpg";
}
function f3()
{
img2.src="four.jpg";
}
function f4()
{
img2.src="three.jpg";
}
function f5()
{
img3.src="six.jpg";
}
function f6()
{
img3.src="five.jpg";
}

</script>
</head>
<body>
<img src="one.jpg" height="50px" width="150px" id="img1" alt="image" onmouseover="f1();" onmouseout="f2();" />
<img src="three.jpg" height="50px" width="150px" id="img2" alt="image" onmouseover="f3();" onmouseout="f4();" />
<img src="five.jpg" height="50px" width="150px" id="img3" alt="image" onmouseover="f5();" onmouseout="f6();" />

</body>
</html>

VB.Net SQL Server Connectivity For Insert New Record

//Create connection object

Dim con1 As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\student\Local Settings\Application Data\Temporary Projects\Databaseconvb\Database1.mdf;Integrated Security=True;User Instance=True")

//Create Command Object

Dim cmd As New System.Data.SqlClient.SqlCommand

cmd.CommandType = System.Data.CommandType.Text
     
cmd.CommandText = "INSERT tbl_user VALUES('" + txt_username.Text + "','" + txt_password.Text + "','" + txt_firstname.Text + "','" + txt_lastname.Text + "','" + gender.Text + "','" + txt_mobile.Text + "','" + txt_emailid.Text + "')"

cmd.Connection = con1

        con1.Open()

        cmd.ExecuteNonQuery()

        con1.Close()

// It will perform the query of inserting new record into the table.

Wednesday, March 6, 2013

Fill Country code in Asp.net


if you have to fill country from the Country table of sql server database to dropdown list then you have to

Create function of fillcountry() in aspx.cs file

System.configuration is used to take connection string from the web.config file of your website.

code written in web.config is here :


<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
<appSettings>
<add key="cnnstr" value="Data Source=THEORY1\SQLEXPRESS;Initial Catalog=userdb;Integrated Security=True"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>



and in aspx.cs file write below code :


using System.Configuration;
using System.Data.SqlClient;
using System.Data;

public partial class AddState : System.Web.UI.Page
{
    SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["cnnstr"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            fillCountry();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("insert into tbl_state values(@statename,@countryid)", cnn);
        cmd.Parameters.AddWithValue("@statename", txtstate.Text);
        cmd.Parameters.AddWithValue("@countryid", ddlcountry.SelectedValue);

        cnn.Open();
        cmd.ExecuteNonQuery();
        cnn.Close();
        txtstate.Text = "";
        txtstate.Focus();

        Response.Write("Record Inserted");
    }
    public void fillCountry()
    {
        SqlCommand cmd = new SqlCommand("select * from tbl_country", cnn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlcountry.DataSource = ds;
        ddlcountry.DataTextField = "countryname";
        ddlcountry.DataValueField = "countryid";
        ddlcountry.DataBind();
    }
}


Explanation of code :-

Execute the function fillCountry() from the page_load event of asp.net c# .

after that the dropdown list is filled so we have to fill it when the first time load of the page so we have to use
 if(!isPostBack) condition checking and inside that execute the fillCountry();

And now we have to insert the record in the datatable of state using button click event of the submit.

That's it.

Thank you.

For Learn C#.Net, ASP.Net, VB.Net Visit OurWebsite