Search This Blog

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

Saturday, October 27, 2012

How to redirect users from domain.com to http:www.domain.com

Here is the answer.


Use .htaccess file in the root directory.

open notepad.exe and create file name .htaccesss


in that file write code


RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^$ http://www.mydomain.com/index.html [L,R=301]



NOTE : FILE MUST BE PUT ON THE ROOT DIRECTORY AND MUST HAVE NAME AS .HTACCESS

Friday, October 19, 2012

Introduction to JQuery

Definition of Jquery 

Jquery : It is a scripting language based on javascript, which contain rich set of built in function so it is very easy to use the jquery in your website. 
                We can create animation on the webpage with the help of jquery. we can also add some interactive programming effects which user wants to see on the webpage using jquery. Now a days jquery is one of the popular scripting language. 

Here some examples are given to show the use of jquery on the website.

Hide and show division or whatever in the division tag like if you want to hide the image then put it inside the division tag.
Division id is #divSample

1000millisecond will taken to show the output on the screen. YOu can change the  Time according to your need into the webpage or web application.

.aspx File

<script type="text/javascript">
  function showbtn()
  {
      $('#divSample').show(1000); 
  }

  function hidebtn()
  {
      $('#divSample').hide(1000); 
  }
</script> 

<body>
<div id="divSample" >
<img src="Image1.jpg" height="200px" width="200px" title="jquery" text="ShowImage" />
</div>
<asp:Button id="b1" runat="server" onclientclick="showbtn();">
</asp:Button>
<asp:Button id="b2" runat="server" onclientclick="hidebtn();" text="HideImage">
</asp:Button>
</body>


The output is wonderful.
so try it your self with littlebit work on this code and you can create innovation in your technology.

I had brief out some other function which can be used as above.

 $('#divSample2').slideUp(2000); 
            
 $('#divSample2').slideDown(2000);


 $('#divSample3').fadeOut(2000); 
            
 $('#divSample3').fadeIn(1100);


Animation with the use of JQuery.

YOu can also create animation with the help of animate function.


$("#divSample").animate({height:500, width:750 , opacity: .7}, 3000, function() {alert("DivSample is having 500px height and 750px width"); });


This will create your division of image large upto 500px height and 750px width.
and after completion of it with opacity of 70%.
 It displays the message that DivSample is having 500px height and 750px width
in the Alert box.
                

Thursday, October 18, 2012

What is JQuery ??? How to use it with Asp.net???

I think you all have to know little bit about the new invention in Technology.or How to use that with the Asp.net.

"JQuery is a cross browser JavaScript library that helps to traverse through HTML elements, event handling, effects(animation) and Ajax interactions."

It is very easy to learn and implement features in out application with the help of JQuery.

Here is Sample Example is given related to it.

Add Script tag into .aspx File for using JQuery on to the Webpage.


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js">  
</script>

OR aspx.cs File 

protected override void Render(HtmlTextWriter writer)
{
this.Page.ClientScript.RegisterClientScriptInclude("jQuery", "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
base.Render(writer);
}

e.g. Display "Hi, Hitesh!" message on the webpage.

.aspx file : 
        
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            
            <script type="text/javascript">
            function hi()
            {
                $("#divSample").append("Hi, Hitesh!");
            }
            </script>

        </head>
        <body>
            <form id="form1" runat="server">
                <div id="divSample">
                </div>
            </form>
        </body>
        </html>
        
And Aspx.cs File
            
protected override void Render(HtmlTextWriter writer)
 {
 this.Page.ClientScript.RegisterClientScriptInclude("jQuery", "http://ajax.google  apis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
 this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "startup", "<s  cript type=\"text/javascript\">hi();</script>");
 base.Render(writer);
}