Please tell me I'm crazy!!! - Reload page does not update textbox values.

M

Mike

Scenario:

1. I dynamically generate a form (using server-side code) with
numerous text boxes that are populated with values from a database.

2. A user enters text all in lower case then clicks save which submits
the page to the server.

3. In the server-side code, I convert the text to all uppercase then
save to a dbf. (Unfortunately I have no control over the database
format and dbf data really needs to be in uppercase because you can't
perform a case-insensitive query on dbf, hence the need for uppercase)

4. I repeat step 1 to redisplay the page and Voila! The page still
displays the value in lower case. BTW, viewstate is set to false.

After pulling my hair out on this one for an insane amount of time, I
came across this article http://support.microsoft.com/?id=316813 which
basically states that what I'm experiencing is by design, which IMHO
totally sucks.

I found a reasonable work-around which is to Response.Redirect to the
same page if IsPostback = True, which forces the page to load from
scratch. But that totally defeats the purpose of this whole ASP.NET
philosophy. So my question is: Am I crazy? Is this really true? Is
there no way to change this behavior? (and while I'm at it, Is Rush
Limbaugh really going to be a regular on Sunday NFL Countdown?)

Someone please tell me there's a better way!!
 
C

Colin Young

You should be able to set the text of the textbox to any value you like in
the code-behind. What does the code for step 1 look like? Is there something
like if (IsPostBack) { ... } in there?

The reason the behaviour is "by design" is that when you submit a form the
server uses the values from the controls on the form to populate the values
of those controls when the form is recreated. I believe that still holds
true for dynamically generated controls, depending on when they are created
in the page life cycle. I would suggest moving the assignment of values out
of the creation method. My best guess without seeing the code is that you
are assigning the values at creation time and then the framework is
overwriting those values later. If you do the assignment after the framework
has restored the viewstate and submitted values you won't have the problem
any more.

Colin
 
J

John Saunders

Mike, how did you uppercase the values? Did you uppercase them in
TextBox.Text? If so, where did you do this? Page_Load? If so, was it within
an "if (page.IsPostBack)" block?
 
M

Mike

Colin,

All my code originates from Page_Load and the subroutine to build my
htmltable is the last subroutine called from Page_Load. (I've included
a reasonably simple example below)

Are you stating that I should split up BuildTable into two
subroutines: one to build the table and one to populate the values? If
so, where should each subroutine be called from? By the way, this
sounds counterintuitive but I'm willing to try anything.

******** BEGIN CODE EXAMPLE ********

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then

Select Case tbAction.Value
Case "Save"
SaveChanges()
End Select

End If

BuildTable()

End Sub


Sub BuildTable()

Dim sQS As String, _
oDT As DataTable, _
oDR As DataRow, _
i As Integer

sQS = "SELECT * FROM tbl_Valuation_CCI"
oDT = SEAAMLogic.FillDataTable(sQS, "sql")

' Set up the variables to build a Table
Dim oTR As HtmlTableRow, _
oTC As HtmlTableCell, _
oTB As HtmlInputText, _
oImg As HtmlImage

For i = 0 To oDT.Rows.Count - 1

oDR = oDT.Rows(i)
oTR = New HtmlTableRow()
oTR.ID = "tr" & oDR(0)

oTC = New HtmlTableCell()
oTC.Width = "50%"
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "100"
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "100"
oTC.BgColor = "#ffffff"
oTC.Align = "center"
oTB = New HtmlInputText()
oTB.ID = "input_" & oDT.Columns(1).ColumnName & "_" & oDR(0)
oTB.Value = ConvNull(oDR(1))
oTB.Attributes.Add("CLASS", "InputCell")
oTB.Attributes.Add("LANGUAGE", "javascript")
oTB.Attributes.Add("ONKEYDOWN", "fCheckKey();")
oTB.Attributes.Add("ONFOCUS", "fSelectRow();")
oTB.Attributes.Add("ONCLICK", "fCancelBubble();")
oTB.Attributes.Add("ONCHANGE", "fValidateData();")
oTC.Controls.Add(oTB)
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "100"
oTC.BgColor = "#ffffff"
oTC.Align = "center"
oTB = New HtmlInputText()
oTB.ID = "input_" & oDT.Columns(2).ColumnName & "_Value_" &
oDR(0)
oTB.Value = ConvNull(oDR(2))
oTB.Attributes.Add("CLASS", "InputCell")
oTB.Attributes.Add("LANGUAGE", "javascript")
oTB.Attributes.Add("ONKEYDOWN", "fCheckKey();")
oTB.Attributes.Add("ONFOCUS", "fSelectRow();")
oTB.Attributes.Add("ONCLICK", "fCancelBubble();")
oTB.Attributes.Add("ONCHANGE", "fValidateData();")
oTC.Controls.Add(oTB)
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "21"
oTC.Align = "center"
oImg = New HtmlImage()
oImg.Style.Add("DISPLAY", "none")
oImg.Src = "Images/ButtonDeleteRecordRight.gif"
oImg.Attributes.Add("TITLE", "Delete row")
oImg.Attributes.Add("CLASS", "ImageButtonMouseUp")
oImg.Attributes.Add("LANGUAGE", "javascript")
oImg.Attributes.Add("ONMOUSEDOWN", "this.className =
'ImageButtonMouseDown';")
oImg.Attributes.Add("ONMOUSEUP", "this.className =
'ImageButtonMouseUp';")
oImg.Attributes.Add("ONMOUSEOUT", "this.className =
'ImageButtonMouseUp';")
oImg.Attributes.Add("ONCLICK", "fDeleteRow();")
oImg.Attributes.Add("CURSOR", "hand")
oImg.Style.Add("POSITION", "relative")
oImg.Style.Add("TOP", "1")
oTC.Controls.Add(oImg)
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "78"
oTR.Cells.Add(oTC)

oTC = New HtmlTableCell()
oTC.Width = "50%"
oTR.Cells.Add(oTC)

tTableDataN.Rows.Add(oTR)

Next

End Sub

******** END CODE EXAMPLE ********
 
M

Mike

John,

I convert the values to uppercase while writing them to a sql table. I
then re-run the BuildTable routine which reads the saved values from
the sql table. I guess an easy solution would be to convert them to
uppercase on the client in the ONCHANGE event, but I really want to
know why rebuilding the htmltable does not update the values in the
htmltable from the sql table.

I've included an example of my code in my reply to Colin. I didn't
include the SaveChanges subroutine but as I stated previously, that's
where the conversion to uppercase occurs.

Please see my reply to Colin for more information.


Mike
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top