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

  • Thread starter \A_Michigan_User\
  • Start date
A

\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!
 
R

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

\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
 
R

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

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

:-(
 
R

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top