Having a little trouble with ViewState

D

D. Shane Fowlkes

I have a form in which clicking the submit button calls a "SaveData" sub
rountine I wrote. The SaveData rountine inserts data from the form into a
table and grabs the ID of the newly inserted record and stores it in a
variable in the routine. The routine writes the data to the table just
fine. But one of the last thing lines in my routine is this:

ViewState("id") = intPurchaseOrderID

The intPurchaseOrderID is the ID of the brand new record. I'm storing this
in viewstate b/c when the form posts to itself, I essentially want the page
to refresh with the form's fields containing the provided data. I'm also
doing this so they can modify their data before "finalizing" it. The form
also contains a "Finalize" button which will create and send an email and
redirect to a new page.

I'm using ViewState("id") to determine IF the page has already gone thru the
save data routine at least once. IF this "id" is detected, I'm trying to
enable the "Finalize" button which is disabled by default AND replace the
INSERT statement with an UPDATE statement so the record is updated instead
of inserting a new record.

My problem is (finally getting to it) is that I cannot seem to "detect" my
ViewState("id") using a IF statement in the Page_Load routine. However,
when I response.write the ViewState("id") to the page, it's
there..containing the correct record ID.

Any ideas as to why the viewstate("id") is being set properly as far as I
can tell but I cannot perform any kind of comparison against it??



Sub Page_Load(Sender As Object, E As EventArgs)
If Not Page.IsPostBack Then
'Call Sub Routine to prefill some dropdowns on form
End If

Dim intReqID As Integer

intReqID = CInt(ViewState("id"))

'No ID was detected....must be a new page loaded...
If intReqID < 1 Then
btnSubmit.Enabled = False
Else
btnSubmit.Enabled = True
End If

End Sub
 
E

Eric Lawrence [MSFT]

I think you're interested in the IsPostBack() function?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top