Can't change the text in a text box?

I'm sure I'm missing something obvious, but I can't figure this out.  I simply want to read in the text from a file, and display it in a textbox.  The user should be able to change the text, and save it back to the original file (overwriting the original text).

This is what I have:

<body>
    <form id="form1" runat="server">
    <div align="center">
        <b>Enter/Edit text for the Autoresponder</b>
        <asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
        <asp:Button ID="BtnSave" runat="server" Text="Button" />
    </div>
    </form>
</body>

and

Imports System.IO

Partial Class Oversight_SetAutoRspns
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sSource = Request.PhysicalApplicationPath & "\archive\responder.txt"
        Dim readFile As String
        readFile = sSource

        Dim Reader As New IO.StreamReader(File.Open(readFile, FileMode.Open))
        txtBox.Text = Reader.ReadToEnd()
        Reader.Close()
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim sTest As String
        sTest = txtBox.Text

        Dim sSource = Request.PhysicalApplicationPath & "\archive\responder.txt"
        Dim Writer As New IO.StreamWriter(File.Open(sSource, FileMode.Create))
        Writer.Write(sTest)
        Writer.Close()
        txtBox.Text = sTest
    End Sub
End Class

 Am I doing something stupid here?

Diane 

0
Mainship
3/5/2008 2:14:21 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

6 Replies
677 Views

Similar Articles

[PageSpeed] 56

The ASPNET user should have modify rights on the file.  This is not by default, so you need to check this.

Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
3/5/2008 2:49:28 AM

Hi Diane,

All i can think of is that your application doesn't have write access to the path... Have you try step by step debugging?

 


Don't forget to click "Mark as Answer" on the post that helped you.
0
amensi
3/5/2008 2:49:40 AM

The user does have modify rights.  I'm not getting an error.  I'm just not getting any change in txtBox.text.  I did debug it line by line.  The value of txtBox.text does not change at any time.   In the second line of BtnSave the value of txtBox.text should be what the user entered.  It isn't.  It remains the same as the text that was read in from the file.  At this point, there has been no attempt yet to write anything.

Diane 

0
Mainship
3/5/2008 2:58:08 AM

 You are not checking for IsPostback. When the user clicks the button, the Page_Load event fires first (loading the existing content from the file into the textbox) and then the button click event fires.

 

0
tlichty
3/5/2008 3:02:01 AM

I know I had to be overlooking something obvious!  That was it.  Thank you, you solved my problem.

Diane 

0
Mainship
3/5/2008 3:23:45 AM

tlichty:

 You are not checking for IsPostback. When the user clicks the button, the Page_Load event fires first (loading the existing content from the file into the textbox) and then the button click event fires.

 

 Good observation. God sometime we skip the basic stuff.




Don't forget to click "Mark as Answer" on the post that helped you.
0
amensi
3/5/2008 3:30:35 AM
Reply:

Similar Artilces:

Can't edit text in the 'Basic text Box' OR 'Rich Text Editor'
have, DNN 3.0.13 installed on Windows server 2003have tried sitting at the server and on a workstationI first tried to edit the text on the home page, the text editor shows up but it is empty/blank, I couldn't put my cursor in the text area and type anything.I have also tried to create a new page and try to edit a text area, same problem.....I have also tried to use the events module and tried to add an event, same problem...PS. preview in not on.Thanks in advance, Peter What browser are you using?Are you using a custom skin?Icthus TechnologiesBuilding Faith on the Internet Im havi...

can't bind text to a text box with text mode password
Hi all, I am using Visual studio 2003.What i am doing a user can edit his account for that reason i have web form with multiple text boxes. I take user information from the data base and bind that to related text boxes....like txtName , txtPhone but text mode for password text box is password. and when i bind data to password text box it remains empty while other boxes with text mode single line show data. dim txtPassword as textbox txtpassword.textmode=password txtpassword.text=reader.getvalue(5) y i don't see ne thing in text box while same code works ok when text mode is single lind ...

why i can't change the text size of pager-text in gridview?
i'm using gridview and want to config the pager ,i set the forecolor of pager-text , it's ok , but there'r problems with other properties like  i can't set the text size , text style( bold , underliner, strike out),and can't apply css.the page which contain this gridview is applied CSS , but it's not work for paager-text ( about size).please help!!! Thx Here is an Example of centering the Text ....similiarly you can bold or use other HTMl Tags .... <PagerStyle NextPageText=" Next &lt;/center&gt;" PrevPageText="&lt;center&gt; Prev "></PagerStyle> Prev " Nex...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

superreview granted: [Bug 233094] [FIX]input text doesn't appear in text box if text box is in floated cell : [Attachment 140654] This fixes all three testcases and the website
David Baron <dbaron@dbaron.org> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 233094: [FIX]input text doesn't appear in text box if text box is in floated cell http://bugzilla.mozilla.org/show_bug.cgi?id=233094 Attachment 140654: This fixes all three testcases and the website http://bugzilla.mozilla.org/attachment.cgi?id=140654&action=edit ------- Additional Comments from David Baron <dbaron@dbaron.org> I'm not crazy about any of the table pseudo frame construction code, and I don't remember my previous objection ...

superreview requested: [Bug 233094] [FIX]input text doesn't appear in text box if text box is in floated cell : [Attachment 140654] This fixes all three testcases and the website
Boris Zbarsky <bzbarsky@mit.edu> has asked David Baron <dbaron@dbaron.org> for superreview: Bug 233094: [FIX]input text doesn't appear in text box if text box is in floated cell http://bugzilla.mozilla.org/show_bug.cgi?id=233094 Attachment 140654: This fixes all three testcases and the website http://bugzilla.mozilla.org/attachment.cgi?id=140654&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> David, what do you think? ...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Can't view form as text ?
Hi When I try to do "View as Text" on the main form in one of my projects I get this message: <quote> Module 'H:\...\unit1.cpp' has open descendents or linked modules. Cannot close </quote> What is the reason for that message ? It's the first time i ever seen it and I don't think I do anything different in this project. Any clues ? Thanks in advance Best regards Asger-P http://Asger-P.dk/software Asger wrote: > When I try to do "View as Text" on the main form in one of my projects > I get this message: > ...

Why can't I change the text of a lable ?
The file default.aspx declares the following.<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="ShareFileHd._default"%> Therefore , I look up the default.aspx.vb.  It declares Protected WithEvents message_welcome As System.Web.UI.WebControls.Label No matter what I set in message_welcome.text, it always shows the same thing.  How can I change the value ?Robert Chu Where are you setting the text, and what code are you using to change it?  David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'B...

Why can't I change the text of a label
In the file default.aspx, the file declared : <%@ Page Language="vb" AutoEventWireup="false" Codebehind="default.aspx.vb" Inherits="ShareFileHd._default"%> In the default.aspx.vb, it declared: Protected WithEvents message_welcome As System.Web.UI.WebControls.Label Then, no matter what I set in message_welcome.text ,  it always showed the same thing. How can I change its value ?    Robert Chu I think your making it to difficult. Check this out .aspx page________________________________________________________- <%@ Page Language="VB" AutoEventWireu...

Enabling button after text changed on text box from form view control
I'm using form view to display some text box that contains user's personal info. There are "save" buttons for each text box which are disable as default. I want to enable them when text is changed on the the text box. I don't know how to write the the JavaScript function to do this task and i also don't know how to call the function from the the textbox control (onchange or ontextchange?). Here is the formview code: <asp:FormView ID="FormView1" runat="server" DataSourceID ="personalSQL"> <ItemTemplate > <ta...

changing the text on text box
hello, i need to build an addon which takes (on mouse click) the text of any given input text box and change it. how do i get theobject of the text box and set my text to its value. thanks... ...

Web resources about - Can't change the text in a text box? - asp.net.web-forms

Resources last updated: 12/14/2015 8:44:29 AM