DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    martin rydman Guest

    Retrieveing TextBox.Text in a WebForm


    Hi all!

    I've never done any ASP, but the promise of Web Forms got me started. I'm
    banging my head against something so trivial I almost hesitate to post it
    here...
    Anyway, I have two Web Forms, and in WebForm2 I want to get the contents
    of 5 textboxes into a structure, pass it to a businesscomponent, and the
    pass the structure back to the first WebForm:

    Private Sub Button1_Click(...)
    Dim MyPubs As New BusinessComponent.bus_Publishers()

    CurrentPub.pub_id = TextBox1.Text
    CurrentPub.pub_name = TextBox2.Text
    CurrentPub.city = TextBox3.Text
    CurrentPub.state = TextBox4.Text
    CurrentPub.country = TextBox5.Text

    MyPubs.UpdatePublisher(CurrentPub)
    Session("CurrentPub") = CurrentPub
    Response.Redirect("webform1.aspx")
    End Sub

    The BusinessComponent is tested and true, and all tests I've tried show that
    even though I've entered new text in the textboxes, the value I get when
    retrieving it like this is the value they got in the Page_Load event, not
    the value entered by the user.

    I guess I'm missing something fundamental here... response... request...
    whatever...

    uh...help, please!

    TIA

    /Martin

  2. #2
    Jacob Grass Guest

    Re: Retrieveing TextBox.Text in a WebForm

    note: I am new to this stuff as well. . .

    I think if you set the ViewState of your page to true, you will be able to
    get the values. The problem is that whenever an event fires, like
    ButtonClick, the pageload event fires first. So, your values are getting
    reset. . . You may also try setting the values of your textboxes in the
    pageload event from inside an If...Then like so:

    If Not IsPostBack Then
    'set values
    End If

    HTH

    Jacob

    "martin rydman" <martin@aprire.se> wrote in message
    news:3bbdc7e1$1@news.devx.com...
    >
    > Hi all!
    >
    > I've never done any ASP, but the promise of Web Forms got me started. I'm
    > banging my head against something so trivial I almost hesitate to post it
    > here...
    > Anyway, I have two Web Forms, and in WebForm2 I want to get the contents
    > of 5 textboxes into a structure, pass it to a businesscomponent, and the
    > pass the structure back to the first WebForm:
    >
    > Private Sub Button1_Click(...)
    > Dim MyPubs As New BusinessComponent.bus_Publishers()
    >
    > CurrentPub.pub_id = TextBox1.Text
    > CurrentPub.pub_name = TextBox2.Text
    > CurrentPub.city = TextBox3.Text
    > CurrentPub.state = TextBox4.Text
    > CurrentPub.country = TextBox5.Text
    >
    > MyPubs.UpdatePublisher(CurrentPub)
    > Session("CurrentPub") = CurrentPub
    > Response.Redirect("webform1.aspx")
    > End Sub
    >
    > The BusinessComponent is tested and true, and all tests I've tried show

    that
    > even though I've entered new text in the textboxes, the value I get when
    > retrieving it like this is the value they got in the Page_Load event, not
    > the value entered by the user.
    >
    > I guess I'm missing something fundamental here... response... request...
    > whatever...
    >
    > uh...help, please!
    >
    > TIA
    >
    > /Martin




  3. #3
    martin rydman Guest

    Re: Retrieveing TextBox.Text in a WebForm


    Hi!

    I just discovered the use of the IsPostBack property.

    For those of you who, like I, stumble into this like a three-year-old, this
    is what aparently happens:

    Everytime an event occurs (typically click) the whole page is posted to the
    server for processing, and then immediately posted back. I had code in my
    Page_Load to initialize my textboxes, and, as far as I can see, the Page_Load
    event is somehow called *again* before the Button1_Click-event, because when
    I enclosed the initialization in an if-statement, the Click-event works:

    If Not Page.IsPostBack Then
    TextBox1.Text = CurrentPub.pub_id
    TextBox2.Text = CurrentPub.pub_name
    TextBox3.Text = CurrentPub.city
    TextBox4.Text = CurrentPub.state
    TextBox5.Text = CurrentPub.country
    End If


    If someone with some insight into this could confirm/correct/expand on this,
    I'd be really greatful!

    TIA!

    /Martin

    "martin rydman" <martin@aprire.se> wrote:
    >
    >Hi all!
    >
    >I've never done any ASP, but the promise of Web Forms got me started. I'm
    >banging my head against something so trivial I almost hesitate to post it
    >here...
    >Anyway, I have two Web Forms, and in WebForm2 I want to get the contents
    >of 5 textboxes into a structure, pass it to a businesscomponent, and the
    >pass the structure back to the first WebForm:
    >
    >Private Sub Button1_Click(...)
    > Dim MyPubs As New BusinessComponent.bus_Publishers()
    >
    > CurrentPub.pub_id = TextBox1.Text
    > CurrentPub.pub_name = TextBox2.Text
    > CurrentPub.city = TextBox3.Text
    > CurrentPub.state = TextBox4.Text
    > CurrentPub.country = TextBox5.Text
    >
    > MyPubs.UpdatePublisher(CurrentPub)
    > Session("CurrentPub") = CurrentPub
    > Response.Redirect("webform1.aspx")
    >End Sub
    >
    >The BusinessComponent is tested and true, and all tests I've tried show

    that
    >even though I've entered new text in the textboxes, the value I get when
    >retrieving it like this is the value they got in the Page_Load event, not
    >the value entered by the user.
    >
    >I guess I'm missing something fundamental here... response... request...
    >whatever...
    >
    >uh...help, please!
    >
    >TIA
    >
    >/Martin



  4. #4
    martin rydman Guest

    Re: Retrieveing TextBox.Text in a WebForm


    Hi Jacob!

    As you may notice, I discovered much the same and posted it while your post
    arrived. Well, you confirmed my own findings... thanks!

    /Martin

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links