Hi
I have developed a web page with some controls. I put all of them in
session variables. I passed this values in the page. When an user
enter some data in form fields and click the buttton , these values
are displaying in next page.after displaying in next page, when click
back button to see my entered values for change , no values are in the
form fields. the fields are empty .I tried with enable view state=true
in controls and at the top of the page.but it doesn't work.
any one help would be appriciated.
Here is the code in two pages.
--------------------------------------------------------------------------------------------------
Default.aspx
<%@ Page Language="C#" AutoEventWireup ="true"
CodeBehind="Def ault.aspx.cs" Inherits="WebAp plication2._Def ault" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body bgcolor="bule">
<form id="form1" runat="server">
<div>
<table cellspacing="1" >
<tr>
<td colspan="300px" >
<table width="700px" border="1">
<tr>
<td>
<tr align="center">
<td align ="center">
<asp:Label ID="lblusername "
runat="server"> FirstName :</asp:Label>
<asp:TextBox ID="txtusername "
runat="server" Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center" bgcolor="Fuchsi a">
<asp:Label ID="lblpassword "
runat="server"> LastName :</asp:Label>
<asp:TextBox ID="txtpassword "
runat="server" Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblcity"
runat="server"> City :</asp:Label>
<asp:TextBox ID="txtcity" runat="server"
Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblstate" BackColor="Aqua "
runat="server"> State :</asp:Label>
<asp:DropDownLi st runat="server"
ID="ddlstate">
<asp:ListItem Text="AZ"/>
<asp:ListItem Text="AL"/>
<asp:ListItem Text="CA"/>
<asp:ListItem Text="DL"/>
<asp:ListItem Text="FL"/>
<asp:ListItem Text="GA"/>
<asp:ListItem Text="IL"/>
<asp:ListItem Text="KE"/>
<asp:ListItem Text="MN"/>
<asp:ListItem Text="ND"/>
<asp:ListItem Text="OH"/>
<asp:ListItem Text="PA"/>
<asp:ListItem Text="SD"/>
<asp:ListItem Text="TX"/>
<asp:ListItem Text="UT"/>
<asp:ListItem Text="VA"/>
</asp:DropDownLis t>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblzip"
runat="server"> Zip :</asp:Label>
<asp:TextBox ID="txtzip" runat="server"
Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblphone"
runat="server"> Phone :</asp:Label>
<asp:TextBox ID="txtphone" runat="server"
Width="100px" BackColor="#009 9FF"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="Label1"
runat="server"> Codeword :</asp:Label>
<asp:DropDownLi st ID="ddlselect"
runat="server" ForeColor="Blue "
BackColor="#FFC CFF">
<asp:ListItem Text=""/>
<asp:ListItem Text="What is your favourite
pet?."/>
<asp:ListItem Text="What is your favourite
country?."/>
<asp:ListItem Text="What is your favourite
movie?."/>
<asp:ListItem Text="What is your favourite
movie?."/>
<asp:ListItem Text="What is your maiden
father name?."/>
</asp:DropDownLis t>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblcodeword "
runat="server"> </asp:Label>
<asp:TextBox ID="txtcodeword "
runat="server" Width="100px" BackColor="Blue Violet"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Button ID="btnok" runat="server"
Text="Submit" onclick="btnok_ Click" />
</td>
</tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
------------------------------------------------------------------------------------------------
Default.aspx.cs
using System;
using System.Collecti ons;
using System.Configur ation;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.H tmlControls;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Xml.Linq ;
using System.Data.Sql Client;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
Page.EnableView State = true;
}
protected void btnok_Click(obj ect sender, EventArgs e)
{
Session["first"] = txtusername.Tex t.Trim();
Session["last"] = txtpassword.Tex t.Trim();
Session["city"] = txtcity.Text.Tr im();
Session["state"] = ddlstate.Select edValue.ToStrin g();
Session["zip"] = txtzip.Text.Tri m();
Session["phone"] = txtphone.Text.T rim();
Session["selectcodeword "] =
ddlselect.Selec tedValue.ToStri ng();
Session["entercodew ord"] = txtcodeword.Tex t.Trim();
Response.Redire ct("WebForm1.as px");
}
}
}
----------------------------------------------------------------------------------------------------
WebForm1.aspx.
using System;
using System.Collecti ons;
using System.Configur ation;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.H tmlControls;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Xml.Linq ;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
string firstname = Session["first"].ToString();
string lastname = Session["last"].ToString();
string cityname = Session["city"].ToString();
string statename = Session["state"].ToString();
string zipcode = Session["zip"].ToString();
string phonenumber = Session["phone"].ToString();
string selectanycodewo rd =
Session["selectcodeword "].ToString();
string enteranycodewor d =
Session["entercodew ord"].ToString();
Response.Write( "you entered :" + "</br>");
Response.Write( "FirstName :" + firstname + "</br>");
Response.Write( "LastName : " + lastname + "</br>");
Response.Write( "CodeWord : " + selectanycodewo rd + "</
br>");
Response.Write( enteranycodewor d + "</br>");
Response.Write( "CityName : " + cityname + "</br>");
Response.Write( "StateName : " + statename + "</br>");
Response.Write( "Zipcode : " + zipcode + "</br>");
Response.Write( "Phone Number :" + phonenumber);
}
protected void btnupdate_Click (object sender, EventArgs e)
{
Response.Redire ct("Default.asp x");
}
protected void btnok_Click(obj ect sender, EventArgs e)
{
Response.Redire ct("WebForm2.as px");
}
}
}
I have developed a web page with some controls. I put all of them in
session variables. I passed this values in the page. When an user
enter some data in form fields and click the buttton , these values
are displaying in next page.after displaying in next page, when click
back button to see my entered values for change , no values are in the
form fields. the fields are empty .I tried with enable view state=true
in controls and at the top of the page.but it doesn't work.
any one help would be appriciated.
Here is the code in two pages.
--------------------------------------------------------------------------------------------------
Default.aspx
<%@ Page Language="C#" AutoEventWireup ="true"
CodeBehind="Def ault.aspx.cs" Inherits="WebAp plication2._Def ault" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body bgcolor="bule">
<form id="form1" runat="server">
<div>
<table cellspacing="1" >
<tr>
<td colspan="300px" >
<table width="700px" border="1">
<tr>
<td>
<tr align="center">
<td align ="center">
<asp:Label ID="lblusername "
runat="server"> FirstName :</asp:Label>
<asp:TextBox ID="txtusername "
runat="server" Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center" bgcolor="Fuchsi a">
<asp:Label ID="lblpassword "
runat="server"> LastName :</asp:Label>
<asp:TextBox ID="txtpassword "
runat="server" Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblcity"
runat="server"> City :</asp:Label>
<asp:TextBox ID="txtcity" runat="server"
Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblstate" BackColor="Aqua "
runat="server"> State :</asp:Label>
<asp:DropDownLi st runat="server"
ID="ddlstate">
<asp:ListItem Text="AZ"/>
<asp:ListItem Text="AL"/>
<asp:ListItem Text="CA"/>
<asp:ListItem Text="DL"/>
<asp:ListItem Text="FL"/>
<asp:ListItem Text="GA"/>
<asp:ListItem Text="IL"/>
<asp:ListItem Text="KE"/>
<asp:ListItem Text="MN"/>
<asp:ListItem Text="ND"/>
<asp:ListItem Text="OH"/>
<asp:ListItem Text="PA"/>
<asp:ListItem Text="SD"/>
<asp:ListItem Text="TX"/>
<asp:ListItem Text="UT"/>
<asp:ListItem Text="VA"/>
</asp:DropDownLis t>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblzip"
runat="server"> Zip :</asp:Label>
<asp:TextBox ID="txtzip" runat="server"
Width="100px"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblphone"
runat="server"> Phone :</asp:Label>
<asp:TextBox ID="txtphone" runat="server"
Width="100px" BackColor="#009 9FF"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="Label1"
runat="server"> Codeword :</asp:Label>
<asp:DropDownLi st ID="ddlselect"
runat="server" ForeColor="Blue "
BackColor="#FFC CFF">
<asp:ListItem Text=""/>
<asp:ListItem Text="What is your favourite
pet?."/>
<asp:ListItem Text="What is your favourite
country?."/>
<asp:ListItem Text="What is your favourite
movie?."/>
<asp:ListItem Text="What is your favourite
movie?."/>
<asp:ListItem Text="What is your maiden
father name?."/>
</asp:DropDownLis t>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="lblcodeword "
runat="server"> </asp:Label>
<asp:TextBox ID="txtcodeword "
runat="server" Width="100px" BackColor="Blue Violet"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Button ID="btnok" runat="server"
Text="Submit" onclick="btnok_ Click" />
</td>
</tr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
------------------------------------------------------------------------------------------------
Default.aspx.cs
using System;
using System.Collecti ons;
using System.Configur ation;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.H tmlControls;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Xml.Linq ;
using System.Data.Sql Client;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
Page.EnableView State = true;
}
protected void btnok_Click(obj ect sender, EventArgs e)
{
Session["first"] = txtusername.Tex t.Trim();
Session["last"] = txtpassword.Tex t.Trim();
Session["city"] = txtcity.Text.Tr im();
Session["state"] = ddlstate.Select edValue.ToStrin g();
Session["zip"] = txtzip.Text.Tri m();
Session["phone"] = txtphone.Text.T rim();
Session["selectcodeword "] =
ddlselect.Selec tedValue.ToStri ng();
Session["entercodew ord"] = txtcodeword.Tex t.Trim();
Response.Redire ct("WebForm1.as px");
}
}
}
----------------------------------------------------------------------------------------------------
WebForm1.aspx.
using System;
using System.Collecti ons;
using System.Configur ation;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.H tmlControls;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Xml.Linq ;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
string firstname = Session["first"].ToString();
string lastname = Session["last"].ToString();
string cityname = Session["city"].ToString();
string statename = Session["state"].ToString();
string zipcode = Session["zip"].ToString();
string phonenumber = Session["phone"].ToString();
string selectanycodewo rd =
Session["selectcodeword "].ToString();
string enteranycodewor d =
Session["entercodew ord"].ToString();
Response.Write( "you entered :" + "</br>");
Response.Write( "FirstName :" + firstname + "</br>");
Response.Write( "LastName : " + lastname + "</br>");
Response.Write( "CodeWord : " + selectanycodewo rd + "</
br>");
Response.Write( enteranycodewor d + "</br>");
Response.Write( "CityName : " + cityname + "</br>");
Response.Write( "StateName : " + statename + "</br>");
Response.Write( "Zipcode : " + zipcode + "</br>");
Response.Write( "Phone Number :" + phonenumber);
}
protected void btnupdate_Click (object sender, EventArgs e)
{
Response.Redire ct("Default.asp x");
}
protected void btnok_Click(obj ect sender, EventArgs e)
{
Response.Redire ct("WebForm2.as px");
}
}
}