Wierd: Can't get .text value of textbox

Discussion in 'ASP .Net' started by VB Programmer, Aug 31, 2004.

  1. I have a textbox on my webform. I can set it, like txt1.text = "hi", but if
    I change the text and click a button to display the current value it RETAINS
    the old value. Any ideas?

    Any ideas?
    VB Programmer, Aug 31, 2004
    #1
    1. Advertising

  2. VB Programmer

    Frank Mamone Guest

    If you set the value of the Textbox programmatically, then when the Page
    Loads it sets it to that value. When you submit it will keep doing it unless
    you include some code to tell it to do it on initial load like this:

    private Page_Load
    {

    if(!IsPostBack)
    {
    txt1.Text = "Hi";

    }

    }

    Not sure of syntax for VB:)


    The IsPostBack property of the Page class detects when the request is a
    postback. That is it has been submitted after initial load.


    Hope this helps,

    Frank

    "VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
    news:...
    > I have a textbox on my webform. I can set it, like txt1.text = "hi", but

    if
    > I change the text and click a button to display the current value it

    RETAINS
    > the old value. Any ideas?
    >
    > Any ideas?
    >
    >
    Frank Mamone, Aug 31, 2004
    #2
    1. Advertising

  3. VB Programmer

    Brian Barnes Guest

    "VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
    news:...
    >I have a textbox on my webform. I can set it, like txt1.text = "hi", but
    >if
    > I change the text and click a button to display the current value it
    > RETAINS
    > the old value. Any ideas?
    >
    > Any ideas?

    Before you initailise the page, are you checking to see if the page has been
    posted back (ie page.ispostback)? Otherwise you are writing the old value
    into the textbox when you intialise the page.

    --
    Brian Barnes
    No Spam Proof e-mail
    Use News Groups
    Brian Barnes, Aug 31, 2004
    #3
  4. You both are correct! Duh.

    Thanks so much guys.

    "Brian Barnes" <> wrote in message
    news:...
    >
    > "VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
    > news:...
    > >I have a textbox on my webform. I can set it, like txt1.text = "hi", but
    > >if
    > > I change the text and click a button to display the current value it
    > > RETAINS
    > > the old value. Any ideas?
    > >
    > > Any ideas?

    > Before you initailise the page, are you checking to see if the page has

    been
    > posted back (ie page.ispostback)? Otherwise you are writing the old value
    > into the textbox when you intialise the page.
    >
    > --
    > Brian Barnes
    > No Spam Proof e-mail
    > Use News Groups
    >
    >
    VB Programmer, Aug 31, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWljaGFlbCBMb3VnaHJ5?=

    Wierd behavior with text box postback

    =?Utf-8?B?TWljaGFlbCBMb3VnaHJ5?=, Jun 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    550
    =?Utf-8?B?TWljaGFlbCBMb3VnaHJ5?=
    Jun 22, 2005
  2. Marc
    Replies:
    12
    Views:
    795
    Peterken
    Jan 3, 2006
  3. ErwinP
    Replies:
    1
    Views:
    712
    ErwinP
    Aug 19, 2005
  4. John Walker

    Unable to Get "Text" Value from Disable Textbox

    John Walker, Oct 13, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    187
    John Walker
    Oct 13, 2005
  5. Markus Fischer
    Replies:
    3
    Views:
    135
    Markus Fischer
    Sep 8, 2004
Loading...

Share This Page