I want to validate the page when I do not select zone in dropdownlist1.
My asp.net page is
<%@ Page Language="C#" MasterPageFile="~/masterPages/Attendence.Master" AutoEventWireup="true" CodeBehind="AttendencePage.aspx.cs" Inherits="DL_PROJECT1.AttendencePage" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">
function Validation()
{
var zoneid=document.getElementById("<%=DropDownList1.ClientID%>");
var userid=document.getElementById("<%=TextBox1.ClientID%>");
var pwd=document.getElementById("<%=TextBox2.ClientID%>");
if(zoneid.value=="" || zoneid.value=="select zone")
{
alert("Please select Zone");
zoneid.focus();
return false;
}
}
</script>
<div>
<table cellpadding="0">
<%----%>
<tr>
<td align="right" style="width:30px">
<asp:Label ID="Label3" runat="server" Text="Location"/>
</td>
<td align="left" style="width:30px">
<asp:DropDownList ID="DropDownList1 "runat="server"
width="135px"/>
</td>
</tr>
<>
<td align="right">
<asp:Label ID="Label1" runat="server" Text="EmployeeID"/>
</td>
<td align="left">
<asp:TextBox ID="TextBox1" runat="server" Width="130px"/>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label2" runat="server" Text="Password"/>
</td>
<td align="left">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"
Width="130px"/>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label4" runat="server" Text="Remark"/>
</td>
<td align="left">
<asp:TextBox ID="TextBox3" runat="server" Width="130px"
TextMode="MultiLine"/>
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="Button1" runat="server" Text="Submit"
OnClientClick=" return Validation();" onclick="Button1_Click"
BackColor="#FFCCFF" BorderColor="#CC99FF"/>
</td>
<td align="left">
<asp:Button ID="Button2" runat="server" Text="Clear"
onclick="Button2_Click" BackColor="#FFCCFF" BorderColor="#CC99FF" />
</td>
</tr>
</table>
<center>
<asp:Label ID="Label5" runat="server" Text="Label" Visible="False"
Font-Bold="True" ForeColor="#000066"/>
</center>
</div>
c# file is:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace DL_PROJECT1
{
public partial class AttendencePage : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=ESS-8\\SQLEXPRESS;Initial Catalog=DL_PROJECT1;Integrated Security=True");
SqlDataReader dr;
SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Focus();
Populate();
}
}
public void Populate()
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ShortName FROM [ZoneTable]", con);
dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "ShortName";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("Select Zone", "Default value"));
con.Close();
dr.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd1 = new SqlCommand("SELECT ECode from Attendence where ECode='" + TextBox1.Text + "' and IncomingDate='" + DateTime.Today + "'", con);
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
Label5.Visible = true;
Label5.Text = "User already taken attendence.";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
DropDownList1.ClearSelection();
dr.Close();
}
else
{
dr.Close();
SqlCommand cmd2 = new SqlCommand("select ECode from AttendenceMaster where ECode='"+TextBox1.Text+"' and Password='"+TextBox2.Text+"'", con);
SqlDataReader dr1 = cmd2.ExecuteReader();
if(dr1.Read())
{
string code = dr1.GetValue(0).ToString();
dr1.Close();
if (TextBox3.Text != "")
{
SqlCommand cmd = new SqlCommand("INSERT INTO Attendence(ECode,IncomingTime,IncomingDate,ZoneName,Remark) VALUES('" + TextBox1.Text + "','" + DateTime.Now.ToString("T") + "','" + DateTime.Now.ToShortDateString() + "','" + DropDownList1.SelectedItem.Text + "','" + TextBox3.Text + "')", con);
cmd.ExecuteNonQuery();
}
else
{
SqlCommand cmd = new SqlCommand("INSERT INTO Attendence(ECode,IncomingTime,IncomingDate,ZoneName) VALUES('" + TextBox1.Text + "','" + DateTime.Now.ToString("T") + "','" + DateTime.Now.ToShortDateString() + "','" + DropDownList1.SelectedItem.Text + "')", con);
cmd.ExecuteNonQuery();
}
Label5.Visible = true;
Label5.Text = "Attendence has been taken.";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
DropDownList1.ClearSelection();
}
else if (DropDownList1.SelectedItem.Text == "")
{
dr1.Close();
Label5.Visible = false;
DropDownList1.Focus();
}
else if (TextBox1.Text == "")
{
dr1.Close();
Label5.Visible = false;
TextBox1.Focus();
}
else if (TextBox2.Text == "")
{
dr1.Close();
Label5.Visible = false;
TextBox2.Focus();
}
else
{
dr1.Close();
Label5.Visible = true;
Label5.Text = "You are not registered.";
}
}
}
catch (SqlException ex)
{
}
finally
{
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
DropDownList1.ClearSelection();
TextBox1.Focus();
Label5.Visible = false;
}
}
}
When I click the button it check javascript and c# file also.But i do not want to run c# file when javascript run popup menu.Actully I want to parse the content by browser then server.