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 2458
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 dumb
mistake
STORED PROCEDURE
CREATE Procedure...
|
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
code to get the values from the database and...
|
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 will work using vb .NET.
Can anyone have a look...
|
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 enter
information about that lab. The keyvalue is...
|
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
9.0.2.3228. I have installed and registered the Sybase...
|
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 application i have added a new web form then script manager...
|
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 framework 2.0.
I've googled everywhere and i think my...
|
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 user can just click on and edit the cell. I have a...
|
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 the results on the Results page be based on that...
|
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 formview i have done, but there is some error
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |