Login Page 1 has
===========
Login
Password
============
User Enters this data and upon success he would be redirected to a
=================================
Details Page
=-------------=
Form View
-----------
Item Template
-------------
Login Id
Password
Name
Additional Details
EditItem Template
------------------
Login Id
Password
Name
Additional Details
Update Details(Button)
Upon succesful login the UserId entered must be carried to the 2nd page where in the details of the user are fetched where the user id = user entered Id.
2 ways to do this
In Login Page
A procedure is being used to validate the user authenticity, Now it can be made to return the UserId back, but iam unable to figure out how this procedure would return the userid upon successful login to 2nd page.
===============
In Login Page
we say
If(procedurename(supplied username,password)) true -->1 then
response.redirect("detailspage.aspx");-->2
I was wondering since 1 determines whetehr the user successfully login then it comes to step 2 so if the control reaches 2 then can we add to response redirect so that the User entered Id will be supplied to the page.
===============
Or the user authentication procedure should return a table i.e it would consist of a row only since if the suer authenticates it would fetch a row. So in the details page the form view should be populated with those table values.
I am just getting confused so kindly help me with your expertise.
The Login Page source
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
<form id="form1" runat="server">
<asp:Login ID="Login1" runat="server">
<LayoutTemplate>
<table border="0" cellpadding="1" cellspacing="0"
style="border-collapse:collapse;">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Log In</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"
ToolTip="Enter Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In"
ValidationGroup="Login1" onclick="LoginButton_Click" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="UserId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="UserId" HeaderText="UserId" ReadOnly="True"
SortExpression="UserId" />
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName" />
<asp:TemplateField HeaderText="Password" SortExpression="Password">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Password") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Password") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [UserDetails]"></asp:SqlDataSource>
</form>
</body>
</html>
The Login Page c# code
using System;
using System.Configuration;
using System.Data;
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;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
public partial class _Default : System.Web.UI.Page
{
private bool DbConnection(string txtUser, string txtPass)
{
//Connection
SqlConnection a;
a=new SqlConnection();
a.ConnectionString=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//Command
SqlCommand b;
b=new SqlCommand("ValidateUser",a);
b.CommandType = CommandType.StoredProcedure;
b.Parameters.Add(new SqlParameter("@UserId",txtUser));
b.Parameters.Add(new SqlParameter("@Password",txtPass));
a.Open();
//Reader
SqlDataReader r;
r=b.ExecuteReader();
if(r.HasRows)
{
a.Close();
return true;
}
else
{
return false;
}
}
protected void LoginButton_Click(object sender, EventArgs e)
{
try
{
if (DbConnection(Login1.UserName, Login1.Password))
{
Response.Redirect("Default2.aspx");
}
}
catch (Exception ec)
{
Login1.FailureText = "Invalid Usernm/Pass " + ec;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
The Details Page C# code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Data.SqlClient;
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;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
FormView1.DefaultMode = FormViewMode.Edit;
}
//protected void Button1_Click(object sender, EventArgs e)
//{
// FormView1.DefaultMode = FormViewMode.Edit;
//}
}
The Details Page Source
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<h3>
<asp:Label ID="Label1" runat="server"
Text="Details Page"></asp:Label>
</h3>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
onpageindexchanging="FormView1_PageIndexChanging">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text="Student Id:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Eval("S_Id") %>'></asp:TextBox>
<asp:Label ID="Label4" runat="server" Text="Login Id: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" ReadOnly="True" height="22px"
width="128px" Text = '<%# Eval("S_Login_Id") %>'>Login Id</asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Name:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" ReadOnly="True" height="22px"
width="128px" Text = '<%# Eval("S_Name") %>'>Name</asp:TextBox>
<asp:Label ID="Label5" runat="server" Text="Class: "></asp:Label>
<asp:TextBox ID="TextBox4" runat="server" ReadOnly="True" height="22px"
width="128px" Text='<%# Eval("CLASS_ID") %>'>Class</asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text="Student Id:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("S_Id") %>'></asp:TextBox>
<asp:Label ID="Label4" runat="server" Text="Login Id: "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" ReadOnly="True" height="22px"
width="128px" Text = '<%# Bind("S_Login_Id") %>'>Login Id</asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Name:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" ReadOnly="True" height="22px"
width="128px" Text = '<%# Bind("S_Name") %>'>Name</asp:TextBox>
<asp:Label ID="Label5" runat="server" Text="Class: "></asp:Label>
<asp:TextBox ID="TextBox4" runat="server" ReadOnly="True" height="22px"
width="128px" Text='<%#Bind("CLASS_ID") %>'>Class</asp:TextBox>
</EditItemTemplate>
</asp:FormView>
<asp:Button ID="Button1" runat="server" Text="Update Details" Width="96px"
/>
<asp:SqlDataSource ID="SqlDataSource1"
selectcommand = "Select [S_Id],[S_Login_Id],[S_Name],[CLASS_ID]
from [STUDENT]
where [S_Id]=@SId"
updatecommand = "Update [STUDENT]
set [S_Id]=@SId,
set [S_Login_Id]=@SLogin_Id,
set [S_Name]=@SName,
set [CLASS_ID]=@Class
where [S_Id]=@SId"
connectionstring = "<%$ ConnectionStrings:ConnectionString %>"
runat="server">
<SelectParameters>
<asp:Parameter Name="SId" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="SId" />
<asp:Parameter Name="SLogin_Id" />
<asp:Parameter Name="SName" />
<asp:Parameter Name="Class" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
As you can see upon the details being displayed i am trying to set the Update Details when buttom pressed to call the form view Edit Template.
But The Page just loads without displaying anything except the Details Page heading and Update Details Button.