Home All Groups Group Topic Archive Search About

Get data, make textBoxes, edit values, and re-save to database. Simple?

Author
1 Feb 2006 4:55 AM
"A_Michigan_User\
I'm using asp.net/vb.net/ado.net to create a very simple user interface.
(Everything works if I use STATICALLY created textBoxes... but not when I
make them DYNAMICALLY.)

1.  Execute a SQL SELECT cmd to retrieve a record.

2.  Loop through the dataReader values, creating textBox boxes dynamically,
adding them to a Panel.
(The database values are placed in these textboxes.)

3. Allow the user to edit 1 of the values in 1 of the textboxes.

4.  When he hits the SUBMIT button... it saves his changes back to the
database with an UPDATE command.

I seem to have everything working... but the values that are getting stored
at the *ORIGINAL* values
(not the new ones that user typed in.)

Seems like I can't get dynamically created controls to return the user's
*NEW* values back to the database.

Help!

Author
1 Feb 2006 8:11 AM
ray.bradbury9
IMHO it seems that you can have done any of these two things:

1.- You create the textboxes and fill the original data in every load
of the web page. Page.IsPostBack missing in the Page_Load?
2.- You may have to add the control to the viewstate.

Anyway, I haven't done any test and you have posted no code, so nothing
is sure.

Show quoteHide quote
> I seem to have everything working... but the values that are getting stored
> at the *ORIGINAL* values
> (not the new ones that user typed in.)
Author
1 Feb 2006 2:33 PM
"A_Michigan_User\
I think all my code is correct...but not *WHERE* it is being called from.

My code is some VERY standard/common database stuff:

Sub LoadData()    ' Creates the new textboxes... and loads them with data
from the database

Sub SaveData()    ' Save the data back to the database

Where *SHOULD* those subs appear?

Page_Load()     ' In the "postback" section
Page_Load()    ' In the "not postback" section
Page_Init()        ' Here?

Should I be "manually" storing my data in ViewState(n) values in LoadData()?
Should I be using those ViewState(n) values in SaveData() to save the data?

I've tried a bazillion different ways... none of which seem to do anything
but "successfully" re-save the
same values that were already in the database.   (Instead of saving the
user's NEW values.)

Thanks

<ray.bradbu***@gmail.com> wrote in message
Show quoteHide quote
news:1138781494.468152.165200@o13g2000cwo.googlegroups.com...
> IMHO it seems that you can have done any of these two things:
>
> 1.- You create the textboxes and fill the original data in every load
> of the web page. Page.IsPostBack missing in the Page_Load?
> 2.- You may have to add the control to the viewstate.
>
> Anyway, I haven't done any test and you have posted no code, so nothing
> is sure.
>
> > I seem to have everything working... but the values that are getting
stored
> > at the *ORIGINAL* values
> > (not the new ones that user typed in.)
>
Author
1 Feb 2006 4:53 PM
ray.bradbury9
I think you are using VB:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            Call LoadData()
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Call SaveData()
    End Sub

    Private Sub LoadData()

    End Sub
    Private Sub SaveData()

    End Sub

About the viewstate: Not sure about this but probably will be ok
setting the enableviewstate property of the textboxes before adding
them to the page.
Author
3 Feb 2006 4:30 AM
"A_Michigan_User\
When placing my LoadData() and SaveData() subs in those places... the
textboxes all contain nothing.

I won't post 100s of lines of code... but seems like the problem area is
most likely:

My LoadData() sub gets the text from the database... and places it in the
newly created Panel1.txtBox0.Text (and 1,2,3) controls
(And also stores it in ViewState(0), ViewState(1), ViewState(2), etc.)

My SaveData() sub tries to save the values ViewState(0), ViewState(1),
etc....
(It can't find Panel1.txtBox0.Text (and 1,2,3) controls... because they are
created "on the fly".)

Doesn't seem to work if I try to manipulate ViewState(n) in my code... or
let the system do it automatically.

:-(


<ray.bradbu***@gmail.com> wrote in message
Show quoteHide quote
news:1138812815.572016.216520@f14g2000cwb.googlegroups.com...
>I think you are using VB:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        If Not Page.IsPostBack Then
>            Call LoadData()
>        End If
>    End Sub
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>        Call SaveData()
>    End Sub
>
>    Private Sub LoadData()
>
>    End Sub
>    Private Sub SaveData()
>
>    End Sub
>
> About the viewstate: Not sure about this but probably will be ok
> setting the enableviewstate property of the textboxes before adding
> them to the page.
>
Author
13 Feb 2006 4:32 PM
ray.bradbury9
a few days ago I saw a FAQ about viewstate in eggheadcaffe. I don´t
remember it, but think that talked about dinamically created controls
and viewstate. hope it helps.