Codeasearch.com - Search your code with us Login | Register | Contact us
  Forums > Asp.Net > Two form in one page.
manikandan
Posted on Sep 5, 2007
Join Date: August 2007
Location: India ( Chennai )
Posts: 8
 
Two form in one page.  

i have login and registration fields in same form. in .net we can use only one form. when i do validation for login fileds the page is not submitting. it ask for data for registration fields also. how to overcome this.

benaya
Posted on Sep 5, 2007
Join Date: June 2007
Location: India ( Chennai )
Posts: 90
 
Re : Two form in one page.  

Hi,
Mani just i want tell u about how to solve.

1) use div tag are table set to runat=server
2) when you are using web forms button for adding and login
set it the visible to the table are div tag.

example :
when u click the login button it will show login table
else it will show register table.


check out my example ok i am sending u design and code page ok. Here i have use for update, change password and logout. I think it will usefull to u.


design page call myAccount.aspx
---------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="myAccount.aspx.cs" Inherits="Login_myAccount" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body topmargin=2 leftmargin=0>
<form id="form1" runat="server">
<table width="720" border="0">
<tr>
<td style="height: 21px">Welcome <asp:Label ID="lblUsername" runat="server"></asp:Label></td>
<td style="height: 21px; width: 199px;">
<asp:LinkButton ID="lnkBtn" runat="server" OnClick="lnkBtn_Click">Change Password</asp:LinkButton></td>
<td style="height: 21px">
<asp:LinkButton ID="lnkbtn_up" runat="server" OnClick="lnkbtn_up_Click">Update Profile</asp:LinkButton></td>
<td style="height: 21px">
<asp:LinkButton ID="lnkbtn_lgt" runat="server" OnClick="lnkbtn_lgt_Click">Logout</asp:LinkButton></td>
</tr>
<tr>
<td>&nbsp;</td>
<td style="width: 199px">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="4" align="left">
<table width="80%" border="0" align="left" id="tblChangepassword" runat="server" visible=false>
<tr>
<td colspan="2">Change Password <div id="lblcpErrorMsg" runat=server visible=false></div></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="40%">Old password</td>
<td>&nbsp;<asp:TextBox ID="txtOldPwd" runat="server" MaxLength="25" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>New password</td>
<td>&nbsp;<asp:TextBox ID="txtNewPwd" runat="server" MaxLength="25" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>Retype the new password </td>
<td>&nbsp;<asp:TextBox ID="txtreNewPwd" runat="server" MaxLength="25" TextMode="Password"></asp:TextBox>&nbsp;<asp:Button
ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=4>
<table width="80%" border="0" align="left" id="tblUpdateProfile" runat="server" visible=false>
<tr>
<td colspan="2">Update Profile <div id="lblupErrorMsg" runat=server visible=false></div></td>
</tr>

<tr>
<td style="width: 209px">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td style="width: 209px">Email Id</td>
<td>&nbsp;<asp:TextBox ID="txtEmailid" runat="server" MaxLength="450"></asp:TextBox></td>
</tr>

<tr>
<td style="width: 209px">Date of birth </td>
<td>&nbsp;<asp:DropDownList ID="selDD" runat="server">
</asp:DropDownList>
-
<asp:DropDownList ID="selMM" runat="server">
</asp:DropDownList>
-
<asp:TextBox ID="txtYear" runat="server" MaxLength="4" Width="28px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 209px">Address</td>
<td>&nbsp;<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" MaxLength="450" Height="99px" Width="247px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 209px">Pincode</td>
<td>&nbsp;<asp:TextBox ID="txtPincode" runat="server" MaxLength="10"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 209px">State</td>
<td>&nbsp;<asp:TextBox ID="txtState" runat="server" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 209px">Country</td>
<td>&nbsp;<asp:TextBox ID="txtCountry" runat="server" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
<asp:HiddenField ID="txthdUid" runat="server" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td style="width: 199px">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>
---------------------------------------------------------------------



code page call myAccount.aspx.cs
---------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Login_myAccount : System.Web.UI.Page
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
string strErrorMsg;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Username"] == null)
{
Response.Redirect("Default.aspx?act=session_expired");
}
lblUsername.Text = Session["Username"].ToString();

if (Page.IsPostBack==false)
{
for (int iDD = 1; iDD <= 31; iDD++)
{
selDD.Items.Add(iDD.ToString());

}
for (int iMM = 1; iMM <= 12; iMM++)
{
selMM.Items.Add(iMM.ToString());
}
}


}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblcpErrorMsg.Visible = true;
if (txtOldPwd.Text == "")
{
lblcpErrorMsg.InnerHtml = "Please enter the Old Password";
}
else if (txtNewPwd.Text == "")
{
lblcpErrorMsg.InnerHtml = "Please enter the New Password";
}
else if (txtreNewPwd.Text == "")
{
lblcpErrorMsg.InnerHtml = "Retype the New Password";
}
else if (txtNewPwd.Text != txtreNewPwd.Text)
{
lblcpErrorMsg.InnerHtml = "Password Mismatch";
}
else
{

SqlConnection Sqlconn = new SqlConnection(strConn);
SqlCommand myCmd = new SqlCommand("Usp_ChangePassword", Sqlconn);

myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1, param2, param3, ObjReturnParam;

param1 = myCmd.Parameters.Add("@VUsername", SqlDbType.VarChar);
param2 = myCmd.Parameters.Add("@VPassword", SqlDbType.VarChar);
param3 = myCmd.Parameters.Add("@OldPassword", SqlDbType.VarChar);
ObjReturnParam = myCmd.Parameters.Add("@rCnt", SqlDbType.Int);

param1.Direction = ParameterDirection.Input;
param2.Direction = ParameterDirection.Input;
param3.Direction = ParameterDirection.Input;
ObjReturnParam.Direction = ParameterDirection.Output;

param1.Value = Session["Username"].ToString();
param2.Value = txtOldPwd.Text;
param3.Value = txtreNewPwd.Text;

Sqlconn.Open();
myCmd.ExecuteNonQuery();
if (ObjReturnParam.Value.ToString() == "0")
{
lblcpErrorMsg.InnerHtml = " - Invalid Password";
}
else
{
lblcpErrorMsg.InnerHtml = " - Updated Successfully";
}
Sqlconn.Close();
}
}
protected void lnkBtn_Click(object sender, EventArgs e)
{
tblChangepassword.Visible = true;
tblUpdateProfile.Visible = false;
}
protected void lnkbtn_lgt_Click(object sender, EventArgs e)
{
Session["Username"] = null;
Response.Redirect("Default.aspx?act=logout");
}
protected void lnkbtn_up_Click(object sender, EventArgs e)
{
tblChangepassword.Visible = false;
tblUpdateProfile.Visible = true;

SqlConnection sqlConn = new SqlConnection(strConn);
SqlCommand myCmdRead = new SqlCommand("Usp_displayProfile", sqlConn);

myCmdRead.CommandType = CommandType.StoredProcedure;
SqlParameter param1, ObjReturnValue1, ObjReturnValue2, ObjReturnValue3;
SqlParameter ObjReturnValue4, ObjReturnValue5, ObjReturnValue6, ObjReturnValue7;

param1 = myCmdRead.Parameters.Add("@VUsername", SqlDbType.VarChar);
ObjReturnValue1 = myCmdRead.Parameters.Add("@VEmailid", SqlDbType.VarChar, 450);
ObjReturnValue2 = myCmdRead.Parameters.Add("@Dob", SqlDbType.DateTime);
ObjReturnValue3 = myCmdRead.Parameters.Add("@VAddress", SqlDbType.VarChar, 450);
ObjReturnValue4 = myCmdRead.Parameters.Add("@VPinCode", SqlDbType.VarChar, 10);
ObjReturnValue5 = myCmdRead.Parameters.Add("@VState", SqlDbType.VarChar, 50);
ObjReturnValue6 = myCmdRead.Parameters.Add("@VCountry", SqlDbType.VarChar, 50);
ObjReturnValue7 = myCmdRead.Parameters.Add("@IUid", SqlDbType.Int);


param1.Direction = ParameterDirection.Input;
ObjReturnValue1.Direction = ParameterDirection.Output;
ObjReturnValue2.Direction = ParameterDirection.Output;
ObjReturnValue3.Direction = ParameterDirection.Output;
ObjReturnValue4.Direction = ParameterDirection.Output;
ObjReturnValue5.Direction = ParameterDirection.Output;
ObjReturnValue6.Direction = ParameterDirection.Output;
ObjReturnValue7.Direction = ParameterDirection.Output;

param1.Value = Session["Username"].ToString();

sqlConn.Open();
myCmdRead.ExecuteReader();
txtEmailid.Text = ObjReturnValue1.Value.ToString();
char[] delimiterChars = { ' ' };
char[] delimiterChars1 = { '/' };
string strdob = ObjReturnValue2.Value.ToString();
string[] strdobSp = strdob.Split(delimiterChars);
string[] strdobSp1 = strdobSp[0].Split(delimiterChars1);

selDD.SelectedValue = strdobSp1[0].ToString();
selMM.SelectedValue = strdobSp1[1].ToString();
txtYear.Text = strdobSp1[2].ToString();

txtAddress.Text = ObjReturnValue3.Value.ToString();
txtPincode.Text = ObjReturnValue4.Value.ToString();
txtState.Text = ObjReturnValue5.Value.ToString();
txtCountry.Text = ObjReturnValue6.Value.ToString();
txthdUid.Value = ObjReturnValue7.Value.ToString();

sqlConn.Close();

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

if (txtEmailid.Text == "")
{
strErrorMsg = "Please enter the Emailid <br />";
}
if (txtYear.Text == "")
{
strErrorMsg += "Please enter the Year <br />";
}
if (txtPincode.Text=="")
{
strErrorMsg += "Please enter the Pincode <br />";
}
if (txtState.Text == "")
{
strErrorMsg += "Please enter the State <br />";
}
if (txtCountry.Text == "")
{
strErrorMsg += "Please enter the Country ";
}

if (strErrorMsg != "")
{
lblupErrorMsg.Visible = true;
lblupErrorMsg.InnerHtml = strErrorMsg;

//lblupErrorMsg.Visible = true;
//lblupErrorMsg.InnerHtml = "Updated successfully.";
}
Response.Write(lblupErrorMsg.InnerHtml.ToString());
/* SqlConnection Sqlconn = new SqlConnection(strConn);
SqlCommand myCmd = new SqlCommand("Usp_selectUpdateProfile", Sqlconn);

myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1, param2, param3, param4, param5, param6, param7, param8;

param1 = myCmd.Parameters.Add("@IUid", SqlDbType.Int);
param2 = myCmd.Parameters.Add("@VUsername", SqlDbType.VarChar);
param3 = myCmd.Parameters.Add("@VEmailid", SqlDbType.VarChar);
param4 = myCmd.Parameters.Add("@VAddress", SqlDbType.VarChar);
param5 = myCmd.Parameters.Add("@VPinCode", SqlDbType.VarChar);
param6 = myCmd.Parameters.Add("@VState", SqlDbType.VarChar);
param7 = myCmd.Parameters.Add("@VCountry", SqlDbType.VarChar);
param8 = myCmd.Parameters.Add("@DDob", SqlDbType.DateTime);

param1.Direction = ParameterDirection.Input;
param2.Direction = ParameterDirection.Input;
param3.Direction = ParameterDirection.Input;
param4.Direction = ParameterDirection.Input;
param5.Direction = ParameterDirection.Input;
param6.Direction = ParameterDirection.Input;
param7.Direction = ParameterDirection.Input;
param8.Direction = ParameterDirection.Input;

param1.Value = txthdUid.Value;
param2.Value = Session["username"].ToString();
param3.Value = txtEmailid.Text;
param4.Value = txtAddress.Text;
param5.Value = txtPincode.Text;
param6.Value = txtState.Text;
param7.Value = txtCountry.Text;
param8.Value = selDD.Text + "/" + selMM.Text + "/" + txtYear.Text;

Sqlconn.Open();
myCmd.ExecuteNonQuery();
Sqlconn.Close();*/
Response.Write("hi");
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("myAccount.aspx");
}
}
-----------------------------------------------------------------------




 Hot Discussion
Go Tech launches Android tablet for Rs 3,999...
Sony targets retailers with quick sales pitches and rew...
Share and discover new activities with Google Schemer...
Samsung gets 9 mn preorders for Galaxy S3: Report...
Google revamps search engine to think like a person...
 
 Discussion Topics
IT News
Php
Javascript
Technology Updates
Asp.Net
MySql
Ajax
Html
Fedora
Software Testing
Asp
Java
General
Flash
Ruby on Rails