473,395 Members | 1,678 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,395 software developers and data experts.

Newb textbox question

I have a textbox on a form that is populated from the database when the form
loads. When I check textbox.Text when the user clicks my submit button, the
value is always what it was when the form loaded, no matter of what the user
changed the text to. Any suggestions?

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = Customers.GetCustomer(Request["Customer"]);
if (ds.Tables[0].Rows.Count == 0)
return;

name.Text = ds.Tables[0].Rows[0][0].ToString();
phone.Text = ds.Tables[0].Rows[0][1].ToString();
contact.Text = ds.Tables[0].Rows[0][2].ToString();
address.Text = ds.Tables[0].Rows[0][3].ToString();
city.Text = ds.Tables[0].Rows[0][4].ToString();
state.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
zip.Text = ds.Tables[0].Rows[0][6].ToString();
notes.Text = ds.Tables[0].Rows[0][7].ToString();
}
protected void editSubmit_Click(object sender, EventArgs e)
{
if (editSubmit.Text == "Edit")
{
name.ReadOnly = false;
phone.ReadOnly = false;
contact.ReadOnly = false;
address.ReadOnly = false;
city.ReadOnly = false;
state.Enabled = true;
zip.ReadOnly = false;
notes.ReadOnly = false;

editSubmit.Text = "Submit";
}
else
{
name.ReadOnly = true;
phone.ReadOnly = true;
contact.ReadOnly = true;
address.ReadOnly = true;
city.ReadOnly = true;
state.Enabled = false;
zip.ReadOnly = true;
notes.ReadOnly = true;

editSubmit.Text = "Edit";
string s = name.Text;

Response.Redirect("CustomerDetails.aspx?Customer=" + s, false);
}
}
Jan 31 '06 #1
2 1472
You're resetting the textbox each time you load the page. Remember, the
clicking 'submit' still causes the Page_Load event to fire. You want to wrap
your load code with an IsPostBack check as follows:

protected void Page_Load(object sender, EventArgs e)
{
//Note the IsPostBack call
if(!this.IsPostBack)
{
DataSet ds = Customers.GetCustomer(Request["Customer"]);
if (ds.Tables[0].Rows.Count == 0)
return;

name.Text = ds.Tables[0].Rows[0][0].ToString();
phone.Text = ds.Tables[0].Rows[0][1].ToString();
contact.Text = ds.Tables[0].Rows[0][2].ToString();
address.Text = ds.Tables[0].Rows[0][3].ToString();
city.Text = ds.Tables[0].Rows[0][4].ToString();
state.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
zip.Text = ds.Tables[0].Rows[0][6].ToString();
notes.Text = ds.Tables[0].Rows[0][7].ToString();
}
}

HTH,

Matt Dinovo
"Eric" <Er**@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
I have a textbox on a form that is populated from the database when the
form
loads. When I check textbox.Text when the user clicks my submit button,
the
value is always what it was when the form loaded, no matter of what the
user
changed the text to. Any suggestions?

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = Customers.GetCustomer(Request["Customer"]);
if (ds.Tables[0].Rows.Count == 0)
return;

name.Text = ds.Tables[0].Rows[0][0].ToString();
phone.Text = ds.Tables[0].Rows[0][1].ToString();
contact.Text = ds.Tables[0].Rows[0][2].ToString();
address.Text = ds.Tables[0].Rows[0][3].ToString();
city.Text = ds.Tables[0].Rows[0][4].ToString();
state.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
zip.Text = ds.Tables[0].Rows[0][6].ToString();
notes.Text = ds.Tables[0].Rows[0][7].ToString();
}
protected void editSubmit_Click(object sender, EventArgs e)
{
if (editSubmit.Text == "Edit")
{
name.ReadOnly = false;
phone.ReadOnly = false;
contact.ReadOnly = false;
address.ReadOnly = false;
city.ReadOnly = false;
state.Enabled = true;
zip.ReadOnly = false;
notes.ReadOnly = false;

editSubmit.Text = "Submit";
}
else
{
name.ReadOnly = true;
phone.ReadOnly = true;
contact.ReadOnly = true;
address.ReadOnly = true;
city.ReadOnly = true;
state.Enabled = false;
zip.ReadOnly = true;
notes.ReadOnly = true;

editSubmit.Text = "Edit";
string s = name.Text;

Response.Redirect("CustomerDetails.aspx?Customer=" + s, false);
}
}

Jan 31 '06 #2
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DataSet ds = Customers.GetCustomer(Request["Customer"]);
if (ds.Tables[0].Rows.Count == 0)
return;

name.Text = ds.Tables[0].Rows[0][0].ToString();
phone.Text = ds.Tables[0].Rows[0][1].ToString();
contact.Text = ds.Tables[0].Rows[0][2].ToString();
address.Text = ds.Tables[0].Rows[0][3].ToString();
city.Text = ds.Tables[0].Rows[0][4].ToString();
state.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
zip.Text = ds.Tables[0].Rows[0][6].ToString();
notes.Text = ds.Tables[0].Rows[0][7].ToString();
} // IsPostback==true means the page is posted back, and you DO NOT
// want to use the original values.
}
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Eric" wrote:
I have a textbox on a form that is populated from the database when the form
loads. When I check textbox.Text when the user clicks my submit button, the
value is always what it was when the form loaded, no matter of what the user
changed the text to. Any suggestions?

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = Customers.GetCustomer(Request["Customer"]);
if (ds.Tables[0].Rows.Count == 0)
return;

name.Text = ds.Tables[0].Rows[0][0].ToString();
phone.Text = ds.Tables[0].Rows[0][1].ToString();
contact.Text = ds.Tables[0].Rows[0][2].ToString();
address.Text = ds.Tables[0].Rows[0][3].ToString();
city.Text = ds.Tables[0].Rows[0][4].ToString();
state.SelectedValue = ds.Tables[0].Rows[0][5].ToString();
zip.Text = ds.Tables[0].Rows[0][6].ToString();
notes.Text = ds.Tables[0].Rows[0][7].ToString();
}
protected void editSubmit_Click(object sender, EventArgs e)
{
if (editSubmit.Text == "Edit")
{
name.ReadOnly = false;
phone.ReadOnly = false;
contact.ReadOnly = false;
address.ReadOnly = false;
city.ReadOnly = false;
state.Enabled = true;
zip.ReadOnly = false;
notes.ReadOnly = false;

editSubmit.Text = "Submit";
}
else
{
name.ReadOnly = true;
phone.ReadOnly = true;
contact.ReadOnly = true;
address.ReadOnly = true;
city.ReadOnly = true;
state.Enabled = false;
zip.ReadOnly = true;
notes.ReadOnly = true;

editSubmit.Text = "Edit";
string s = name.Text;

Response.Redirect("CustomerDetails.aspx?Customer=" + s, false);
}
}

Jan 31 '06 #3

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

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
0
by: David E. | last post by:
So as a programmer, what's the best thing to study? EJB? How much of the J2EE or Enterprise architecture is necessary to no? I guess I need a good overview for a newb like me... thanks.. --...
3
by: Walter | last post by:
But I'm stumped..... I've got a windows 2000 server and I am trying to set up PHPBB on it using a mysql database.. I am very inexperienced on this..... Ive installed mysql V4.0.20d and I can...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
6
by: Sean Berry | last post by:
Hello all I have build a list that contains data in the form below -- simplified for question -- myList = ,, ...] I have a function which takes value3 from the lists above and returns...
1
by: Qwert | last post by:
Hello, two questions about the following code (.aspx file): Why doesn't the 'Text' property of control 'Label1' get changed in the function 'SetLabelText()'? How do I trigger the...
2
by: Adriano | last post by:
hello, I have TextBox1 and TextBox2 in my win. app, is it possibe to make my "Left Arrow Key" act like "Shift Tab"(focus the previous control) only in the case the cursor comes to the begining...
6
by: tommydogs | last post by:
I am just starting out with AxWebBrowser and need help with a simple application. I just want to navigate to a web page, then read in source code. Here's what I have so far: Private Sub...
2
by: python programming newb | last post by:
Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.