473,378 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to maintain values in text box controls in C#

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="Default.aspx.cs" Inherits="WebApplication2._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 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="Fuchsia">
<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:DropDownList 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:DropDownList>
</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="#0099FF"></asp:TextBox>
</td>
</tr>
<tr align="center">
<td align="center">
<asp:Label ID="Label1"
runat="server">Codeword :</asp:Label>
<asp:DropDownList ID="ddlselect"
runat="server" ForeColor="Blue"
BackColor="#FFCCFF">
<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:DropDownList>
</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="BlueViolet"></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.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 WebApplication2
{
public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
Page.EnableViewState = true;
}

protected void btnok_Click(object sender, EventArgs e)
{
Session["first"] = txtusername.Text.Trim();
Session["last"] = txtpassword.Text.Trim();
Session["city"] = txtcity.Text.Trim();
Session["state"] = ddlstate.SelectedValue.ToString();
Session["zip"] = txtzip.Text.Trim();
Session["phone"] = txtphone.Text.Trim();
Session["selectcodeword"] =
ddlselect.SelectedValue.ToString();
Session["entercodeword"] = txtcodeword.Text.Trim();
Response.Redirect("WebForm1.aspx");

}

}

}
----------------------------------------------------------------------------------------------------
WebForm1.aspx.
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;

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object 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 selectanycodeword =
Session["selectcodeword"].ToString();
string enteranycodeword =
Session["entercodeword"].ToString();

Response.Write("you entered :" + "</br>");
Response.Write("FirstName :" + firstname + "</br>");
Response.Write("LastName : " + lastname + "</br>");
Response.Write("CodeWord : " + selectanycodeword + "</
br>");
Response.Write(enteranycodeword + "</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.Redirect("Default.aspx");
}

protected void btnok_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}
}
}
Aug 17 '08 #1
0 2843

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robert Phillips | last post by:
I have a Panel control containing a few TextBox controls. The Panel is originally enabled, I enter data into the TextBox controls. When I submit, the Panel is disabled during the PostBack and the...
0
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the...
0
by: Ozer | last post by:
Hi guys, I need some help. In my datagrid's updatecommand event i'm trying to get textboxes values and also do it. But when i update the values in textboxes and fire the event, I can't get the...
1
by: Tom wilson | last post by:
Yes, I'm sorry, it's me again. :) Yesterday I went through hell trying to figure out why my aspx pages wouldn't maintain state. I had a simple example I (we) eventually got to work. What...
2
by: Kiran Kumar Pinjala | last post by:
Hi, May be this is silly, or I just need a second pair eyes to look at this. I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code...
2
by: Pipo | last post by:
Nobody knows how to get the values provided in the client can be read in the user-control? If have made a Web Custom Control with 2 textboxes and 1 dropdownlist. The user fills in my control (the...
0
by: rockdale | last post by:
Hi, All: I dynamic add an arrow up/down image in OnItemDataBound event for my datagrid, it works fine. But I have another textbox which trigger postback and doing something, after this event get...
1
by: Andy B | last post by:
I have this code: protected void EditEventsWizard_NextButtonClick(object sender, WizardNavigationEventArgs e) { //get the values from the DetailsView TextBox StartTime =...
1
by: bgernon | last post by:
I have a table that consists of two rows with three cells each row. The cells contain textboxes. I am able to successfully add a new row with textboxes when a button is clicked. The problem is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.