Professional Web Applications Themes

Using TextBox.Text - ASP.NET General

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(); }...

  1. #1

    Default Using TextBox.Text

    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();

    }




    Steve Guest

  2. #2

    Default Re: Using TextBox.Text

    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]" <microsoft.com> wrote in message
    news:3f492019$microsoft.com... 
    rights. 
    > what 
    >
    >[/ref]


    Steve Guest

  3. #3

    Default Re: Using TextBox.Text

    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" <com> wrote in message
    news:zm92b.254116$bloor.is.net.cable.rogers.com... 
    > rights. [/ref][/ref]
    the [/ref][/ref]
    the [/ref][/ref]
    reloads 
    > >
    > >[/ref]
    >
    >[/ref]


    Jim Guest

  4. #4

    Default Re: Using TextBox.Text

    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)" <com> wrote in message
    news:phx.gbl... 
    > are 
    > that 
    > box [/ref][/ref]
    you [/ref]
    > are [/ref][/ref]
    event 
    > > rights. [/ref][/ref]
    "\News.txt",false); [/ref][/ref]
    message [/ref]
    > other [/ref][/ref]
    no [/ref][/ref]
    Thanks. [/ref][/ref]
    news:np82b.253792$bloor.is.net.cable.rogers.com... [/ref]
    > button, [/ref]
    > click 
    > > "\News.txt",false); 
    > >
    > >[/ref]
    >
    >[/ref]


    Steve Guest

  5. #5

    Default Re: Using TextBox.Text

    Ahhh, I C. Thanks

    Steve

    "Jim Blizzard [MSFT]" <microsoft.com> wrote in message
    news:3f497458$microsoft.com... 
    user 
    page 
    from 
    rights. 
    > first [/ref]
    in 
    > having [/ref][/ref]
    'then' [/ref]
    > when [/ref]
    > the [/ref]
    > changes [/ref][/ref]
    is [/ref]
    > the [/ref][/ref]
    no [/ref][/ref]
    message [/ref][/ref]
    post [/ref]
    > textbox 
    > > event [/ref][/ref]
    no [/ref][/ref]
    Thanks. [/ref][/ref]
    news:zm92b.254116$bloor.is.net.cable.rogers.com... [/ref][/ref]
    idea... 
    > > "\News.txt",false); 
    > > message [/ref][/ref]
    (in [/ref]
    > repro? [/ref][/ref]
    confers 
    > > Thanks. 
    > > news:np82b.253792$bloor.is.net.cable.rogers.com... [/ref][/ref]
    I [/ref]
    > it 
    > >
    > >[/ref]
    >
    >[/ref]


    Steve Guest

  6. #6

    Default Re: Using TextBox.Text

    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.


    -------------------- 
    >user [/ref]
    any 
    >page 
    >from 
    >rights. 
    >> first [/ref]
    >in 
    >> having [/ref]
    >'then' 
    >> when [/ref][/ref]
    which 
    >> changes [/ref]
    >is [/ref][/ref]
    from [/ref]
    >no [/ref]
    >message [/ref]
    >post 
    >> textbox [/ref]
    >no [/ref]
    >Thanks. [/ref]
    >news:zm92b.254116$bloor.is.net.cable.rogers.com.. . [/ref]
    >idea... [/ref]
    >(in 
    >> repro? [/ref]
    >confers [/ref][/ref]
    a [/ref]
    >I [/ref][/ref]
    and 
    >>
    >>[/ref]
    >
    >
    >[/ref]

    Jim Guest

Similar Threads

  1. Selecting all text in a textbox?
    By Harry Simpson in forum ASP.NET General
    Replies: 4
    Last Post: January 24th, 04:34 PM
  2. TextBox.Text value not changing when it is prepopulated
    By Paul M. Frazier, Ph.D. in forum ASP.NET General
    Replies: 3
    Last Post: May 27th, 07:17 PM
  3. resize a point text textbox without distorting the text
    By niko_wilkesmann@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 3
    Last Post: July 27th, 11:37 AM
  4. Encapsulating text in a textbox?
    By Dirk in forum Microsoft Access
    Replies: 3
    Last Post: August 28th, 10:08 PM
  5. Get text in TextBox without pressing Enter key
    By mg in forum ASP.NET General
    Replies: 5
    Last Post: July 14th, 02:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139