Problems with Webform textbox

  • Thread starter Jeffery J. Morgan
  • Start date
J

Jeffery J. Morgan

If anyone has an idea about this, I am open to suggestions....

I have a webform that has a textbox. I set it's text property in the page
load area to data that is in the a dataset, but not bound to the text box. I
use a data row, get the value and then set the text property to the value
of the data row.

It is a data entry application. I have a button on the form that will save
the data back to the database, but when I go to get the text property of the
textbox, it always have the initial value and doesn't see what is entered in
the text box. I am not sure why it doesn't see the updated or change entries
in the text box.

Thanks in advanced.

Jeff
 
K

Ken Cox [Microsoft MVP]

Hi Jeff,

Make sure that you aren't refilling the text value on postbacks in the page
load event. Just wrap that part in If not ispostback() .

Ken
 
J

Jeffery J. Morgan

Hi Ken,

Thanks for that, but I am filling in the data during a postback. Maybe I
need to find another way, but the form is painted, the user makes a choice
from a listbox and then the value is filled in during the postback. Is there
another way that I am to do this?

Thanks
Jeff
 
K

Ken Cox [Microsoft MVP]

Hi Jeff,

Could you provide a small sample of code that exhibits the problem? This
shouldn't be too hard.

Ken
 
J

Jeffery J. Morgan

Goes something like this...

if not .ispost back then
'fill in a list box with choices
txtcomments.visible=false

else
'select the data for the record choose...

Dim cmdComments As New OleDb.OleDbCommand("Select * from tblcomment
where permnum='" & strPermnum & "' and term=4", cn)
Dim dsComments As New DataSet
Dim daComments As New OleDb.OleDbDataAdapter(cmdComments)
dacomments.Fill(dsComments, "comments")
Dim drComments As DataRow
If dsComments.Tables(0).Rows.Count > 0 Then
dr = dsComments.Tables(0).Rows(0)
txtComments.Text = dr.Item("Comment")
Else
txtComments.Text = ""
End If

DataGrid1.PageSize = 50
DataGrid1.DataSource = ds
DataGrid1.DataBind()

endif


In the btnSave routine....

Dim cmdo1 As New OleDb.OleDbCommand("Delete * from tblcomment where
permnum='" & strPermnum & "' and term=4", cnAccess)

cmdo1.ExecuteNonQuery()


cmdo1.CommandText = "Insert into tblcomment (Permnum, Comment, term) values
('" & strPermnum & "','" & txtcomments.Text & "', 4)"

cmdo1.ExecuteNonQuery()

cnAccess.Close()

Response.Redirect("frmstudent.aspx")



In the last routine, the txtcomments.text is the original value that was put
into it in the postback.



Thanks

Jeff
 
S

Sven

When you set the value every time Page_Load is called, you will always
see the
initial value, when a callback function is called. Use Page.IsPostBack
to set the value only, when Page_Load is called the first time.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top