Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
//I have this button of get owner's name in my form , but i'm unable to get it instead it gives the validation error messages , like i have used regular expression validation and so on.....//
//Problem is in Button3//

.aspxPage


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="add_fmember.aspx.cs" Inherits="housing1.WebForm5" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">

.auto-style9 {
width: 341px;
text-align: center;
}
.auto-style31 {
width: 128px;
}
.auto-style10 {
width: 341px;
height: 26px;
text-align: center;
}
.auto-style32 {
height: 26px;
width: 128px;
}
.auto-style11 {
height: 26px;
}
.auto-style24 {
color: #FF0000;
}
.auto-style16 {
width: 341px;
text-align: center;
height: 23px;
}
.auto-style33 {
width: 128px;
height: 23px;
}
.auto-style13 {
height: 23px;
}

.auto-style8 {
width: 100%;
background-color: #CCFFFF;
}
.auto-style34 {
width: 182px;
}
</style>

<script type="text/javascript">

function myFunction() {

alert("You have exceeded the members entered");


}




</script>

<script>
function setAge1(d) {
var age1 = moment().diff(d, 'years');
$('#TextBoxA1').val(age1);
}

$(function () {
$('.manual1').change(function () {
setAge1(moment($(this).val()));
});
});
</script>
</head>
<body>
<form id="form1" runat="server">



Flat No <asp:TextBox ID="TextBoxFN" runat="server" >
<asp:RequiredFieldValidator ID="RequiredFieldValidator21" runat="server" ControlToValidate="TextBoxFN" ErrorMessage="Flat No is Required" ForeColor="Red">






Primary Member Name <asp:TextBox ID="TextBoxPMN" runat="server" >
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Get Owner's Name" />
First_Name <asp:TextBox ID="TextBoxFN1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxFN1" ErrorMessage="Name is Required" ForeColor="Red">
Middle_Name <asp:TextBox ID="TextBoxMN1" runat="server">
Last_Name <asp:TextBox ID="TextBoxLN1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="TextBoxLN1" ErrorMessage="Last Name is Required" ForeColor="Red">
Mobile Number <asp:TextBox ID="TextBoxMO1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="TextBoxMO1" ErrorMessage="Mobile Number is Required" ForeColor="Red">


Email <asp:TextBox ID="TextBoxE1" runat="server">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBoxE1" ErrorMessage="Invalid Email" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
Date Of Birth <asp:TextBox ID="TextBoxDOB1" runat="server" Class="manual1">
(dd/mm/yyyy)
Age <asp:TextBox ID="TextBoxA1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="TextBoxA1" ErrorMessage="Age is required" ForeColor="Red">
Educational Qualification <asp:TextBox ID="TextBoxEQ1" runat="server">
Office Address <asp:TextBox ID="TextBoxOA1" runat="server" TextMode="MultiLine">
Native Address <asp:TextBox ID="TextBoxNA1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server" ControlToValidate="TextBoxNA1" ErrorMessage="Native Address is required" ForeColor="Red">
PAN Card Number <asp:TextBox ID="TextBoxPCN1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator18" runat="server" ControlToValidate="TextBoxPCN1" ErrorMessage="PAN Card No Is Required" ForeColor="Red">
Aadhar Card Number <asp:TextBox ID="TextBoxACN1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator19" runat="server" ControlToValidate="TextBoxACN1" ErrorMessage="Aadhar number is Required" ForeColor="Red">
Religion <asp:TextBox ID="TextBoxR1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator20" runat="server" ControlToValidate="TextBoxR1" ErrorMessage="Religion is Mandatory" ForeColor="Red">
Business/Job <asp:RadioButtonList ID="RadioButtonListBJ1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Business">Business
<asp:ListItem Value="Job">Job

 
Married/UnMarried <asp:RadioButtonList ID="RadioButtonListMU1" runat="server" RepeatDirection="Horizontal" Width="171px">
<asp:ListItem Value="Married">Married
<asp:ListItem Value="Unmarried">Unmarried

 
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ADD" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="BACK" />
 




<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/webform1.aspx">Go To Menu




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



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


namespace housing1
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
conn.Open();
String select = "Select count(Primary_Name) from Family_Member where Flat='" + TextBoxFN.Text + "'";
SqlCommand com1 = new SqlCommand(select, conn);
String select1 = "Select No_Of_Members from Primary_Member where Flat='" + TextBoxFN.Text + "'";
SqlCommand com2 = new SqlCommand(select1, conn);
int b = Convert.ToInt32(com1.ExecuteScalar());
int a = Convert.ToInt32(com2.ExecuteScalar());
if (b == a)
{
//Response.Write(a);

ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myFunction();", true);
}

else
{

try
{


String insertQuery1 = "insert into Family_Member ( Primary_Name , Flat ,First_Name , Middle_Name , Last_Name , Mobile_No , Email, DOB , Age , Education , Office_Add , Native_Add , PAN_Card , Aadhar_Card , Business_Job , Married_Unmarried) values( @prname , @flat , @fname , @mname , @lname , @mobile , @email , @dob , @age , @edu , @office_add , @native_add , @PAN , @Aadhar , @BJ , @MUm )";
SqlCommand com = new SqlCommand(insertQuery1, conn);
com.Parameters.AddWithValue("@prname", TextBoxPMN.Text);
com.Parameters.AddWithValue("@flat", TextBoxFN.Text);
com.Parameters.AddWithValue("@fname", TextBoxFN1.Text);
com.Parameters.AddWithValue("@mname", TextBoxMN1.Text);
com.Parameters.AddWithValue("@lname", TextBoxLN1.Text);
com.Parameters.AddWithValue("@mobile", TextBoxMO1.Text);
com.Parameters.AddWithValue("@email", TextBoxE1.Text);
com.Parameters.AddWithValue("@dob", TextBoxDOB1.Text);
com.Parameters.AddWithValue("@age", TextBoxA1.Text);
com.Parameters.AddWithValue("@edu", TextBoxEQ1.Text);
com.Parameters.AddWithValue("@office_add", TextBoxOA1.Text);
com.Parameters.AddWithValue("@native_add", TextBoxNA1.Text);
com.Parameters.AddWithValue("@PAN", TextBoxPCN1.Text);
com.Parameters.AddWithValue("@Aadhar", TextBoxACN1.Text);
com.Parameters.AddWithValue("@BJ", RadioButtonListBJ1.SelectedValue);
com.Parameters.AddWithValue("@MUm", RadioButtonListMU1.SelectedValue);



com.ExecuteNonQuery();
//ScriptManager.RegisterStartupScript(this, GetType(), "myFunction1", "myFunction()1;", true);

Response.Write("Data Updated Successfully");
// Response.Redirect("webform1.aspx?nom=" + TextBoxNOM.Text);

conn.Close();
}

catch (Exception ex)
{
Response.Write("Error" + ex.ToString());

}
}
}

protected void Button2_Click(object sender, EventArgs e)
{
TextBoxFN.Text = "";
TextBoxPMN.Text = "";
TextBoxFN1.Text = "";
TextBoxMN1.Text = "";
TextBoxLN1.Text = "";
TextBoxMO1.Text = "";
TextBoxE1.Text = "";
TextBoxDOB1.Text = "";
TextBoxA1.Text = "";
TextBoxE1.Text = "";
TextBoxOA1.Text = "";
TextBoxNA1.Text = "";
TextBoxPCN1.Text = "";
TextBoxACN1.Text = "";
TextBoxEQ1.Text = "";
TextBoxR1.Text = "";
RadioButtonListBJ1.SelectedIndex = -1;
RadioButtonListMU1.SelectedIndex = -1;
}

protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
conn.Open();

String str = "select First_Name from Primary_Member where Flat='" + TextBoxFN.Text.Trim() + "'";
SqlCommand comm = new SqlCommand(str, conn);
SqlDataReader reader = comm.ExecuteReader();
if (reader.Read())
{
TextBoxPMN.Text = reader["First_Name"].ToString();
reader.Close();
}

}
}
}
Posted

1 solution

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900