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. Advertisements

  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. Advertisements

  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. Advertisements

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?YmFzdWxhc3o=?=

    how can i get value from a template textbox?

    =?Utf-8?B?YmFzdWxhc3o=?=, Jun 23, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    565
    =?Utf-8?B?YmFzdWxhc3o=?=
    Jun 23, 2005
  2. mintboy
    Replies:
    0
    Views:
    806
    mintboy
    Jan 24, 2006
  3. Replies:
    3
    Views:
    939
    George Ter-Saakov
    Feb 23, 2007
  4. AGSHAR
    Replies:
    1
    Views:
    728
    AGSHAR
    May 31, 2008
  5. agb

    writing two textbox's text in one textbox

    agb, Aug 26, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    270
    Ken Cox [Microsoft MVP]
    Aug 27, 2003
  6. ErwinP
    Replies:
    1
    Views:
    1,117
    ErwinP
    Aug 19, 2005
  7. John Walker

    Unable to Get "Text" Value from Disable Textbox

    John Walker, Oct 13, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    294
    John Walker
    Oct 13, 2005
  8. Steve
    Replies:
    4
    Views:
    418
    Steve
    Feb 7, 2006
Loading...