Heres what I want to do...User types into a texbox, clicks a button, the
button saves that text to a file. The problem is that when I click the
submit button, any changes made to the textbox are lost, and it reloads what
was previously there.
Any ideas?
try
{
StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false);
sw.Write(TextBox1.Text);
sw.Flush();
sw.Close();
} 5 2346
It's in the click event of the button. Below is the basic idea...
private void OnLoad(object sender, System.EventArgs e)
{
if(sender.GetType()==typeof(System.Web.UI.WebContr ols.TextBox))
{
TextBox temp = (TextBox)sender;
StreamReader sr = new StreamReader(sVirtualDir + @"\News.txt");
temp.Text = sr.ReadToEnd();
sr.Close();
}
}
private void Submit_Click(object sender, System.EventArgs e)
{
try
{
StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false);
sw.Write(TextBox1.Text);
sw.Flush();
sw.Close();
}
catch(HttpException ex)
{
Response.Write(ex.Message);
}
}
"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message
news:3f********@news.microsoft.com... Well, that's interesting. Where is the code (below) located (in other words, what event handler is it in)? Can you post a simple repro?
Thanks, bliz -- Jim Blizzard | http://weblogs.asp.net/jblizzard Sr .NET Developer Specialist Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no
rights. Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:np********************@news01.bloor.is.net.ca ble.rogers.com... Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are lost, and it reloads what was previously there.
Any ideas?
try {
StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false);
sw.Write(TextBox1.Text);
sw.Flush();
sw.Close();
}
Are you pre-populating TextBox1 with something? In your first post you
said, "when I click the submit button, any changes made to the textbox are
lost, and it reloads what was previously there."
How / when does the "previous" text get put in TextBox1?
Also, what are you doing with the "temp" textbox in the page_load event
handler?
bliz
--
Jim Blizzard | http://weblogs.asp.net/jblizzard
Sr .NET Developer Specialist
Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message
news:zm********************@news01.bloor.is.net.ca ble.rogers.com... It's in the click event of the button. Below is the basic idea...
private void OnLoad(object sender, System.EventArgs e)
{
if(sender.GetType()==typeof(System.Web.UI.WebContr ols.TextBox))
{
TextBox temp = (TextBox)sender;
StreamReader sr = new StreamReader(sVirtualDir + @"\News.txt");
temp.Text = sr.ReadToEnd();
sr.Close();
}
}
private void Submit_Click(object sender, System.EventArgs e)
{
try
{
StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false);
sw.Write(TextBox1.Text);
sw.Flush();
sw.Close();
}
catch(HttpException ex)
{
Response.Write(ex.Message);
}
} "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message news:3f********@news.microsoft.com... Well, that's interesting. Where is the code (below) located (in other words, what event handler is it in)? Can you post a simple repro?
Thanks, bliz -- Jim Blizzard | http://weblogs.asp.net/jblizzard Sr .NET Developer Specialist Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights. Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:np********************@news01.bloor.is.net.ca ble.rogers.com... Heres what I want to do...User types into a texbox, clicks a button,
the button saves that text to a file. The problem is that when I click
the submit button, any changes made to the textbox are lost, and it
reloads what was previously there.
Any ideas?
try {
StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false);
sw.Write(TextBox1.Text);
sw.Flush();
sw.Close();
}
Sorry, Im new to ASP, but why does determining whether or not it's the first
run matter? When I click submit, is it not able to locally grab whats in
the textbox? If thats the case, can it be done somehow locally w/out having
to go back to the server...
"MS News (MS ILM)" <sq**********@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl... do you do anything like that in your pageload?
if ( ! Page.IsPostBack ) // First time load or Not if vb.net ... 'then' {
} else {
} it looks like you are loading the same thing over and over again even when you post back
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:t4*********************@news02.bloor.is.net.c able.rogers.com... The Load event populates the textbox with data in a text file, which the user can then change, and when the submit button is pressed the changes are applied and saved back to the text file. However what is happening is that the text gets loaded fine in OnLoad, but if I delete everything from the box then hit submit...the data justs gets placed back in the box as if no changes were saved.
"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message news:3f******@news.microsoft.com... Are you pre-populating TextBox1 with something? In your first post
you said, "when I click the submit button, any changes made to the textbox are lost, and it reloads what was previously there."
How / when does the "previous" text get put in TextBox1?
Also, what are you doing with the "temp" textbox in the page_load
event handler?
bliz -- Jim Blizzard | http://weblogs.asp.net/jblizzard Sr .NET Developer Specialist Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights. Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:zm********************@news01.bloor.is.net.ca ble.rogers.com... > It's in the click event of the button. Below is the basic idea... > > > private void OnLoad(object sender, System.EventArgs e) > > { > > if(sender.GetType()==typeof(System.Web.UI.WebContr ols.TextBox)) > > { > > TextBox temp = (TextBox)sender; > > StreamReader sr = new StreamReader(sVirtualDir + @"\News.txt"); > > temp.Text = sr.ReadToEnd(); > > sr.Close(); > > } > > } > > private void Submit_Click(object sender, System.EventArgs e) > > { > > try > > { > > StreamWriter sw = new StreamWriter(sVirtualDir +
@"\News.txt",false); > > sw.Write(TextBox1.Text); > > sw.Flush(); > > sw.Close(); > > } > > catch(HttpException ex) > > { > > Response.Write(ex.Message); > > } > > } > > > > "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in
message > news:3f********@news.microsoft.com... > > Well, that's interesting. Where is the code (below) located (in other > > words, what event handler is it in)? Can you post a simple repro? > > > > Thanks, > > bliz > > -- > > Jim Blizzard | http://weblogs.asp.net/jblizzard > > Sr .NET Developer Specialist > > Microsoft > > > > Your Potential. Our Passion. > > > > This posting is provided "AS IS" with no warranties, and confers
no > rights. > > Please reply to newsgroups only, so that others may benefit.
Thanks. > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > >
news:np********************@news01.bloor.is.net.ca ble.rogers.com... > > > Heres what I want to do...User types into a texbox, clicks a button, the > > > button saves that text to a file. The problem is that when I click the > > > submit button, any changes made to the textbox are lost, and it reloads > > what > > > was previously there. > > > > > > Any ideas? > > > > > > try > > > { > > > > > > StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false); > > > > > > sw.Write(TextBox1.Text); > > > > > > sw.Flush(); > > > > > > sw.Close(); > > > > > > } > > > > > > > > > > > > > > > > > >
Ahhh, I C. Thanks
Steve
"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message
news:3f********@news.microsoft.com... Hi Steve,
You need to check to see if it's a postback. (It's a postback when the
user clicks the submit button). The Page_Load event is always fired before any Button event handling. As a result, by the time you get to your button click handler, you've already wiped out the text in the textbox in the
page load.
If it's a postback, don't populate the textbox... it contains the value
from the user.
If it's not a postback, populate the textbox yourself...
See the code snipit from "MS NEWS" below.
Hope this helps! bliz
-- Jim Blizzard | http://weblogs.asp.net/jblizzard Sr .NET Developer Specialist Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no
rights. Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:H3*********************@news02.bloor.is.net.c able.rogers.com... Sorry, Im new to ASP, but why does determining whether or not it's the first run matter? When I click submit, is it not able to locally grab whats
in the textbox? If thats the case, can it be done somehow locally w/out having to go back to the server...
"MS News (MS ILM)" <sq**********@hotmail.com> wrote in message news:uA**************@tk2msftngp13.phx.gbl... do you do anything like that in your pageload?
if ( ! Page.IsPostBack ) // First time load or Not if vb.net ...
'then' {
} else {
} it looks like you are loading the same thing over and over again even when you post back
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:t4*********************@news02.bloor.is.net.c able.rogers.com... > The Load event populates the textbox with data in a text file, which the > user can then change, and when the submit button is pressed the changes are > applied and saved back to the text file. However what is happening
is that > the text gets loaded fine in OnLoad, but if I delete everything from the box > then hit submit...the data justs gets placed back in the box as if
no > changes were saved. > > > "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in
message > news:3f******@news.microsoft.com... > > Are you pre-populating TextBox1 with something? In your first
post you > > said, "when I click the submit button, any changes made to the textbox are > > lost, and it reloads what was previously there." > > > > How / when does the "previous" text get put in TextBox1? > > > > Also, what are you doing with the "temp" textbox in the page_load event > > handler? > > > > bliz > > -- > > Jim Blizzard | http://weblogs.asp.net/jblizzard > > Sr .NET Developer Specialist > > Microsoft > > > > Your Potential. Our Passion. > > > > This posting is provided "AS IS" with no warranties, and confers
no > rights. > > Please reply to newsgroups only, so that others may benefit.
Thanks. > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > >
news:zm********************@news01.bloor.is.net.ca ble.rogers.com... > > > It's in the click event of the button. Below is the basic
idea... > > > > > > > > > private void OnLoad(object sender, System.EventArgs e) > > > > > > { > > > > > > if(sender.GetType()==typeof(System.Web.UI.WebContr ols.TextBox)) > > > > > > { > > > > > > TextBox temp = (TextBox)sender; > > > > > > StreamReader sr = new StreamReader(sVirtualDir + @"\News.txt"); > > > > > > temp.Text = sr.ReadToEnd(); > > > > > > sr.Close(); > > > > > > } > > > > > > } > > > > > > private void Submit_Click(object sender, System.EventArgs e) > > > > > > { > > > > > > try > > > > > > { > > > > > > StreamWriter sw = new StreamWriter(sVirtualDir + @"\News.txt",false); > > > > > > sw.Write(TextBox1.Text); > > > > > > sw.Flush(); > > > > > > sw.Close(); > > > > > > } > > > > > > catch(HttpException ex) > > > > > > { > > > > > > Response.Write(ex.Message); > > > > > > } > > > > > > } > > > > > > > > > > > > "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message > > > news:3f********@news.microsoft.com... > > > > Well, that's interesting. Where is the code (below) located
(in other > > > > words, what event handler is it in)? Can you post a simple repro? > > > > > > > > Thanks, > > > > bliz > > > > -- > > > > Jim Blizzard | http://weblogs.asp.net/jblizzard > > > > Sr .NET Developer Specialist > > > > Microsoft > > > > > > > > Your Potential. Our Passion. > > > > > > > > This posting is provided "AS IS" with no warranties, and
confers no > > > rights. > > > > Please reply to newsgroups only, so that others may benefit. Thanks. > > > > > > > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > > > > news:np********************@news01.bloor.is.net.ca ble.rogers.com... > > > > > Heres what I want to do...User types into a texbox, clicks a button, > > the > > > > > button saves that text to a file. The problem is that when
I click > > the > > > > > submit button, any changes made to the textbox are lost, and it > > reloads > > > > what > > > > > was previously there. > > > > > > > > > > Any ideas? > > > > > > > > > > try > > > > > { > > > > > > > > > > StreamWriter sw = new StreamWriter(sVirtualDir + > @"\News.txt",false); > > > > > > > > > > sw.Write(TextBox1.Text); > > > > > > > > > > sw.Flush(); > > > > > > > > > > sw.Close(); > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
You're welcome. Thanks for using the newsgroups!
--
Jim Blizzard | http://weblogs.asp.net/jblizzard
Sr .NET Developer Evangelist
Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.
-------------------- From: "Steve S" <hi***@rogersNOSPAM.com> Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Re: Using TextBox.Text
Ahhh, I C. Thanks
Steve
"Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in message news:3f********@news.microsoft.com... Hi Steve,
You need to check to see if it's a postback. (It's a postback when the user clicks the submit button). The Page_Load event is always fired before
any Button event handling. As a result, by the time you get to your button click handler, you've already wiped out the text in the textbox in the page load.
If it's a postback, don't populate the textbox... it contains the value from the user.
If it's not a postback, populate the textbox yourself...
See the code snipit from "MS NEWS" below.
Hope this helps! bliz
-- Jim Blizzard | http://weblogs.asp.net/jblizzard Sr .NET Developer Specialist Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights. Please reply to newsgroups only, so that others may benefit. Thanks.
"Steve S" <hi***@rogersNOSPAM.com> wrote in message news:H3*********************@news02.bloor.is.net.c able.rogers.com... > Sorry, Im new to ASP, but why does determining whether or not it's the first > run matter? When I click submit, is it not able to locally grab whatsin > the textbox? If thats the case, can it be done somehow locally w/out having > to go back to the server... > > > "MS News (MS ILM)" <sq**********@hotmail.com> wrote in message > news:uA**************@tk2msftngp13.phx.gbl... > > do you do anything like that in your pageload? > > > > if ( ! Page.IsPostBack ) // First time load or Not if vb.net ...'then' > > { > > > > } > > else > > { > > > > } > > it looks like you are loading the same thing over and over again even when > > you post back > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > > news:t4*********************@news02.bloor.is.net.c able.rogers.com... > > > The Load event populates the textbox with data in a text file,
which the > > > user can then change, and when the submit button is pressed the changes > > are > > > applied and saved back to the text file. However what is happeningis > > that > > > the text gets loaded fine in OnLoad, but if I delete everything
from the > > box > > > then hit submit...the data justs gets placed back in the box as ifno > > > changes were saved. > > > > > > > > > "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote inmessage > > > news:3f******@news.microsoft.com... > > > > Are you pre-populating TextBox1 with something? In your firstpost > you > > > > said, "when I click the submit button, any changes made to the textbox > > are > > > > lost, and it reloads what was previously there." > > > > > > > > How / when does the "previous" text get put in TextBox1? > > > > > > > > Also, what are you doing with the "temp" textbox in the page_load > event > > > > handler? > > > > > > > > bliz > > > > -- > > > > Jim Blizzard | http://weblogs.asp.net/jblizzard > > > > Sr .NET Developer Specialist > > > > Microsoft > > > > > > > > Your Potential. Our Passion. > > > > > > > > This posting is provided "AS IS" with no warranties, and confersno > > > rights. > > > > Please reply to newsgroups only, so that others may benefit.Thanks. > > > > > > > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > > > >news:zm********************@news01.bloor.is.net.c able.rogers.com... > > > > > It's in the click event of the button. Below is the basicidea... > > > > > > > > > > > > > > > private void OnLoad(object sender, System.EventArgs e) > > > > > > > > > > { > > > > > > > > > > if(sender.GetType()==typeof(System.Web.UI.WebContr ols.TextBox)) > > > > > > > > > > { > > > > > > > > > > TextBox temp = (TextBox)sender; > > > > > > > > > > StreamReader sr = new StreamReader(sVirtualDir + @"\News.txt"); > > > > > > > > > > temp.Text = sr.ReadToEnd(); > > > > > > > > > > sr.Close(); > > > > > > > > > > } > > > > > > > > > > } > > > > > > > > > > private void Submit_Click(object sender, System.EventArgs e) > > > > > > > > > > { > > > > > > > > > > try > > > > > > > > > > { > > > > > > > > > > StreamWriter sw = new StreamWriter(sVirtualDir + > @"\News.txt",false); > > > > > > > > > > sw.Write(TextBox1.Text); > > > > > > > > > > sw.Flush(); > > > > > > > > > > sw.Close(); > > > > > > > > > > } > > > > > > > > > > catch(HttpException ex) > > > > > > > > > > { > > > > > > > > > > Response.Write(ex.Message); > > > > > > > > > > } > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > "Jim Blizzard [MSFT]" <ji******@online.microsoft.com> wrote in > message > > > > > news:3f********@news.microsoft.com... > > > > > > Well, that's interesting. Where is the code (below) located(in > > other > > > > > > words, what event handler is it in)? Can you post a simple repro? > > > > > > > > > > > > Thanks, > > > > > > bliz > > > > > > -- > > > > > > Jim Blizzard | http://weblogs.asp.net/jblizzard > > > > > > Sr .NET Developer Specialist > > > > > > Microsoft > > > > > > > > > > > > Your Potential. Our Passion. > > > > > > > > > > > > This posting is provided "AS IS" with no warranties, andconfers > no > > > > > rights. > > > > > > Please reply to newsgroups only, so that others may benefit. > Thanks. > > > > > > > > > > > > > > > > > > "Steve S" <hi***@rogersNOSPAM.com> wrote in message > > > > > > > news:np********************@news01.bloor.is.net.ca ble.rogers.com... > > > > > > > Heres what I want to do...User types into a texbox, clicks
a > > button, > > > > the > > > > > > > button saves that text to a file. The problem is that when
I > > click > > > > the > > > > > > > submit button, any changes made to the textbox are lost,
and it > > > > reloads > > > > > > what > > > > > > > was previously there. > > > > > > > > > > > > > > Any ideas? > > > > > > > > > > > > > > try > > > > > > > { > > > > > > > > > > > > > > StreamWriter sw = new StreamWriter(sVirtualDir + > > > @"\News.txt",false); > > > > > > > > > > > > > > sw.Write(TextBox1.Text); > > > > > > > > > > > > > > sw.Flush(); > > > > > > > > > > > > > > sw.Close(); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sporke13 |
last post by:
I have used stored procedures to insert and select but for some reason I can
not get this code to update records. Please help I must have made a...
|
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the...
|
by: Rob |
last post by:
Hi all,
I am having trouble converting the code below (found on
http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a
format that...
|
by: sck10 |
last post by:
Hello,
I am creating a form for users to enter information about a lab and the
members of the lab. I have one form (FormView) that they use to...
|
by: Metal2You |
last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that
accesses a Sybase database back end. We're using Sybase SQL Anywhere...
|
by: Mukesh |
last post by:
Hi i want to use AJAX.net in my Existing Application
I have already installed the ajax .net
..net 3.0
and using VS 2005
in the old...
|
by: Sister Ray |
last post by:
I'm trying to create a simple form that sends an email using my
company's exchange server. I'm using the System.Net.Mail Namespace of
the .net...
|
by: toddw607 |
last post by:
Hi all!
I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the...
|
by: brwalias |
last post by:
Hi,
using .net 2
sql server 2005
Here is my situation:
I'm passing a variable in the url from a selection on Page A and need
to display...
|
by: IReallyNeedHelp |
last post by:
I have saved the questions using AddQuestion.aspx page i have created but i don't know how to display it and calculate their score.
this is the...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |