473,883 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Failed to load ViewState

I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message of "No records found" which is correct, because my filter is still looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut ionStep.Execute ()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean& completedSynchr onously)

The only way to not get this error is to reload the page completely.

What could be my problem??

Thanks in advance,

John Kirksey


Nov 17 '05 #1
9 21654
Hi,

it is hard to say without seeing your code. Post the relevant code.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
"John Kirksey" <jo**********@v erizon.net> wrote in message news:Oi******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message of "No records found" which is correct, because my filter is still looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut ionStep.Execute ()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean& completedSynchr onously)

The only way to not get this error is to reload the page completely.

What could be my problem??

Thanks in advance,

John Kirksey


Nov 17 '05 #2
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree of
your page. Seeing that you mention a "no records found" message leads me to
suspect that you are either adding extra, or more likely removing controls
from your page in this specific case. When resubmitting, the viewstate does
not contain values for those removed controls, but those controls are on the
page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica

"John Kirksey" <jo**********@v erizon.net> wrote in message
news:Oi******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a page that uses an in-place editable DataGrid that supports sorting
and paging. EnableViewState is turned ON. At the top of the page are several
search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to
"NO" (in this case a checkbox). In this scenario the search returns one
result. If I then check the checkbox ("YES") and save it, I now get my
message of "No records found" which is correct, because my filter is still
looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into
which viewstate is being loaded must match the control tree that was used to
save viewstate during the previous request. For example, when adding
controls dynamically, the controls added during a post-back must match the
type and position of the controls added during the initial request.
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at
System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut i
onStep.Execute( )
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
completedSynchr onously)
The only way to not get this error is to reload the page completely.
What could be my problem??
Thanks in advance,
John Kirksey
Nov 17 '05 #3
Hi,

it is hard to say without seeing your code. Post the relevant code.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
"John Kirksey" <jo**********@v erizon.net> wrote in message news:Oi******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message of "No records found" which is correct, because my filter is still looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut ionStep.Execute ()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean& completedSynchr onously)

The only way to not get this error is to reload the page completely.

What could be my problem??

Thanks in advance,

John Kirksey


Nov 17 '05 #4
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree of
your page. Seeing that you mention a "no records found" message leads me to
suspect that you are either adding extra, or more likely removing controls
from your page in this specific case. When resubmitting, the viewstate does
not contain values for those removed controls, but those controls are on the
page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica

"John Kirksey" <jo**********@v erizon.net> wrote in message
news:Oi******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a page that uses an in-place editable DataGrid that supports sorting
and paging. EnableViewState is turned ON. At the top of the page are several
search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to
"NO" (in this case a checkbox). In this scenario the search returns one
result. If I then check the checkbox ("YES") and save it, I now get my
message of "No records found" which is correct, because my filter is still
looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into
which viewstate is being loaded must match the control tree that was used to
save viewstate during the previous request. For example, when adding
controls dynamically, the controls added during a post-back must match the
type and position of the controls added during the initial request.
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at
System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut i
onStep.Execute( )
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
completedSynchr onously)
The only way to not get this error is to reload the page completely.
What could be my problem??
Thanks in advance,
John Kirksey
Nov 17 '05 #5
Ed,

You are correct, in summary this error happens when a row is removed from
the page, but from my testing it appears to only be the last row. My page
consists of a datagrid, but when the page refreshes the page is reloaded, so
the controls are rebuilt, right? I'm not sure if you want the aspx or the
codebehind, but the page is fairly large so I'll be happy to post whichever
one would help with diagnosing my problem.

John


"Edwin Kusters" <NO***********@ xs4all.nl> wrote in message
news:OO******** ******@TK2MSFTN GP11.phx.gbl...
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree of your page. Seeing that you mention a "no records found" message leads me to suspect that you are either adding extra, or more likely removing controls
from your page in this specific case. When resubmitting, the viewstate does not contain values for those removed controls, but those controls are on the page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica

Nov 17 '05 #6
Ed,

You are correct, in summary this error happens when a row is removed from
the page, but from my testing it appears to only be the last row. My page
consists of a datagrid, but when the page refreshes the page is reloaded, so
the controls are rebuilt, right? I'm not sure if you want the aspx or the
codebehind, but the page is fairly large so I'll be happy to post whichever
one would help with diagnosing my problem.

John


"Edwin Kusters" <NO***********@ xs4all.nl> wrote in message
news:OO******** ******@TK2MSFTN GP11.phx.gbl...
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree of your page. Seeing that you mention a "no records found" message leads me to suspect that you are either adding extra, or more likely removing controls
from your page in this specific case. When resubmitting, the viewstate does not contain values for those removed controls, but those controls are on the page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica

Nov 17 '05 #7
John,

Both preferably. But it would be nice if we were able to actually run it and
toy with it. So if your trim it down as much as possible while still
preserving the behavior it would be great. If you really need to access a
database for it then please use Northwind. The thing you should look at is
if you can turn viewstate off for the object you are removing before the
page is rendered. The viewstate is saved just before the actual rendering
takes place (and loaded during page initialization) . Somewhere outside that
range objects are added or deleted.

Regards,
Edwin Kusters

Also have a quick search on the discussion groups with google for your error
you'll find a few simulair ones.

"John Kirksey" <jo**********@v erizon.net> wrote in message
news:ue******** ******@tk2msftn gp13.phx.gbl...
Ed,

You are correct, in summary this error happens when a row is removed from
the page, but from my testing it appears to only be the last row. My page
consists of a datagrid, but when the page refreshes the page is reloaded, so the controls are rebuilt, right? I'm not sure if you want the aspx or the
codebehind, but the page is fairly large so I'll be happy to post whichever one would help with diagnosing my problem.

John


"Edwin Kusters" <NO***********@ xs4all.nl> wrote in message
news:OO******** ******@TK2MSFTN GP11.phx.gbl...
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree
of
your page. Seeing that you mention a "no records found" message leads me

to
suspect that you are either adding extra, or more likely removing

controls from your page in this specific case. When resubmitting, the viewstate

does
not contain values for those removed controls, but those controls are on

the
page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica


Nov 17 '05 #8
John,

Both preferably. But it would be nice if we were able to actually run it and
toy with it. So if your trim it down as much as possible while still
preserving the behavior it would be great. If you really need to access a
database for it then please use Northwind. The thing you should look at is
if you can turn viewstate off for the object you are removing before the
page is rendered. The viewstate is saved just before the actual rendering
takes place (and loaded during page initialization) . Somewhere outside that
range objects are added or deleted.

Regards,
Edwin Kusters

Also have a quick search on the discussion groups with google for your error
you'll find a few simulair ones.

"John Kirksey" <jo**********@v erizon.net> wrote in message
news:ue******** ******@tk2msftn gp13.phx.gbl...
Ed,

You are correct, in summary this error happens when a row is removed from
the page, but from my testing it appears to only be the last row. My page
consists of a datagrid, but when the page refreshes the page is reloaded, so the controls are rebuilt, right? I'm not sure if you want the aspx or the
codebehind, but the page is fairly large so I'll be happy to post whichever one would help with diagnosing my problem.

John


"Edwin Kusters" <NO***********@ xs4all.nl> wrote in message
news:OO******** ******@TK2MSFTN GP11.phx.gbl...
Without seeing the actual code it's hard to say exactly but the error as
such is rather explicit.

The viewstate stored in your page does not match the initial control tree
of
your page. Seeing that you mention a "no records found" message leads me

to
suspect that you are either adding extra, or more likely removing

controls from your page in this specific case. When resubmitting, the viewstate

does
not contain values for those removed controls, but those controls are on

the
page by default so there is a mismatch. This is (one scenario) how this
error could occur.

If you need more help you really have to post the page source for us.

Hope this helps,
Edwin Kusters
Hot ITem Informatica


Nov 17 '05 #9
Here is my code. As I said, it's pretty long. Basically it consists of a paginated Datagrid using template columns bound to data pulled back from the GetAllData() function. We store pagination info in our own session object (which we use across multiple applications.) We also use a DAL for data access.

Here is the codebehind. The aspx is is a separate post.

' ----------------------------------------------------------------------------------------------------------

' Function Name: Page_Load

' Description: Overridden local Page_Load sub. Takes the base Page_Load one step further and runs the

' specific processing for this page.

' ----------------------------------------------------------------------------------------------------------

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

'Put user code to initialize the page here

lblMessage.Visi ble = False

If Not IsPostBack Then

'don't need to see the data controls yet

dgProvUpdate.Vi sible = False

tblNav.Visible = False

'for now store the key pagination variables in the ViewState

ViewState("Page Number") = 1

ViewState("Page Count") = 0

ViewState("Firs tOnPage") = -1

'the first time we load the page we'll order by date and get all data

ViewState("Sort Field") = "PROV_LAST ASC, PROV_FIRST ASC, PROV_MI"

ViewState("Sort Direction") = "ASC"

ViewState("Requ eryList") = True

'Get the pagination variables from ViewState

mblnRequeryList = ViewState("Requ eryList")

mintPageNumber = ViewState("Page Number")

mintNumPages = ViewState("Page Count")

mintFirstOnPage = ViewState("Firs tOnPage")

mstrOrderBy = ViewState("Sort Field")

mstrOrderDir = ViewState("Sort Direction")

mintNumItems = ViewState("Item Count")

'here the user came here from the search provider page

If Len(Request.Que ryString("ProvK ey")) Then

Dim strProvKey As String, strSpecID As String

Dim intKeyPage As Integer

mstrCustomerID = Request.QuerySt ring("customeri d")

strProvKey = Request.QuerySt ring("provkey")

strSpecID = Request.QuerySt ring("specid")

ViewState("Requ eryList") = False

'make sure the data controls are visible

dgProvUpdate.Vi sible = True

tblNav.Visible = True

'get the provider data

Call GetAllData(mstr CustomerID, strProvKey, intKeyPage)

Call BindGrid()

'Set the page no. to the page found in intKeyPage from GetAllData

ViewState("Page Number") = intKeyPage

mintPageNumber = ViewState("Page Number")

Call BindGrid()

Dim dgi As DataGridItem

Dim lblTemp As Label

Dim intRowID As Integer = 0

'Loop through the datagrid and find the provkey. When we do, mark it as editable.

For Each dgi In dgProvUpdate.It ems

lblTemp = dgi.FindControl ("NUM")

If lblTemp.Text = strProvKey Then

dgProvUpdate.Ed itItemIndex = intRowID

'Get the TaxID Type so we can use it to preselect the correct choice in the TaxIDType dropdown

ViewState("TaxI DType") = UCase(CType(dgi .FindControl("l blTaxIDType"), Label).Text)

ViewState("Spec ID") = UCase(CType(dgi .FindControl("S PECID"), Label).Text)

're-bind the grid

If mintNumItems > 0 Then

Call BindGrid()

Call LoadJumpToCombo ()

End If

Exit For

End If

intRowID += 1

Next

'Load the cust spec drop down and pre-select the current spec

Call LoadCustSpecCom bo()

Dim i As Integer

For i = 0 To cboCustSpec.Ite ms.Count - 1

If cboCustSpec.Ite ms(i).Value = strSpecID Then

cboCustSpec.Ite ms(i).Selected = True

Exit For

End If

Next

hfnAction.Value = "SetFocus_" & intRowID

End If

Else

mstrCustomerID = Request.Form("t xtCustomerID")

ViewState("Requ eryList") = False

'Get the pagination variables from ViewState

mblnRequeryList = ViewState("Requ eryList")

mintPageNumber = ViewState("Page Number")

mintNumPages = ViewState("Page Count")

mintFirstOnPage = ViewState("Firs tOnPage")

mstrOrderBy = ViewState("Sort Field")

mstrOrderDir = ViewState("Sort Direction")

mintNumItems = ViewState("Item Count")

'user elected to do a group enroll/unenroll

If Request.Form("h fnAction") = "UpdateEnrollme nts" Then

Call UpdateEnrollmen ts()

hfnAction.Value = ""

End If

'User elected to delete one or more providers

If Request.Form("h fnAction") = "DeleteProvider " Then

Call DeleteProvider( )

hfnAction.Value = ""

End If

'Load cboCustSpec for this customer

If Request.Form("h fnAction") = "GetSpec" And Len(mstrCustome rID) Then

'make sure the data controls are invisible

dgProvUpdate.Vi sible = False

tblNav.Visible = False

Call LoadCustSpecCom bo()

hfnAction.Value = "SpecFocus"

End If

End If

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: UpdateEnrollmen ts

'Description:

'Returns: Nothing

'-----------------------------------------------------------------------------------------------------------

Protected Sub UpdateEnrollmen ts()

Dim strSql As String, strEnrollKeyLis t As String = "", strUnEnrollKeyL ist As String = "", _

strReason1KeyLi st As String = "", strReason2KeyLi st As String = "", strReason3KeyLi st As String = "", _

strReason4KeyLi st As String = ""

Dim objDAL As Object

Dim dgiTemp As DataGridItem

Dim chkTemp As CheckBox

Dim cboTemp As DropDownList

Dim objRS As ADODB.Recordset

mstrCustomerID = Request.Form("t xtCustomerID")

strEnrollKeyLis t = ""

strUnEnrollKeyL ist = ""

strSql = ""

'get the value of the ENROLLED checkbox

For Each dgiTemp In dgProvUpdate.It ems

chkTemp = dgiTemp.FindCon trol("chkEnroll ")

cboTemp = dgiTemp.FindCon trol("cboEnroll edReason")

'if it's checked, add it to the enroll list. Otherwise, add it to the unenroll list

If chkTemp.Checked = True Then

strEnrollKeyLis t += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

Else

strUnEnrollKeyL ist += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

End If

If chkTemp.Checked = True Then

strReason1KeyLi st += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

Else

'if the item is not checked, get the value anyway

Select Case cboTemp.Selecte dItem.Value

Case 1

strReason1KeyLi st += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

Case 2

strReason2KeyLi st += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

Case 3

strReason3KeyLi st += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

Case 4

strReason4KeyLi st += "'" & CType(dgiTemp.F indControl("NUM "), Label).Text & "',"

End Select

End If

Next

'If the keylist exists, lop off the extra comma and create the SQL for it.

If strEnrollKeyLis t.Length > 0 Then

strEnrollKeyLis t = strEnrollKeyLis t.Remove(strEnr ollKeyList.Leng th - 1, 1)

strSql += "Update Provider set Enrolled = 'Y' where PROVKEY in (" & strEnrollKeyLis t & ") and customerid = '" & mstrCustomerID & "';"

End If

If strUnEnrollKeyL ist.Length > 0 Then

strUnEnrollKeyL ist = strUnEnrollKeyL ist.Remove(strU nEnrollKeyList. Length - 1, 1)

strSql += "Update Provider set Enrolled = 'N' where PROVKEY in (" & strUnEnrollKeyL ist & ") and customerid = '" & mstrCustomerID & "';"

End If

If strReason1KeyLi st.Length > 0 Then

strReason1KeyLi st = strReason1KeyLi st.Remove(strRe ason1KeyList.Le ngth - 1, 1)

strSql += "Update Provider set EnrolledReasonI D = 1 where PROVKEY in (" & strReason1KeyLi st & ") and customerid = '" & mstrCustomerID & "';"

End If

If strReason2KeyLi st.Length > 0 Then

strReason2KeyLi st = strReason2KeyLi st.Remove(strRe ason2KeyList.Le ngth - 1, 1)

strSql += "Update Provider set EnrolledReasonI D = 2 where PROVKEY in (" & strReason2KeyLi st & ") and customerid = '" & mstrCustomerID & "';"

End If

If strReason3KeyLi st.Length > 0 Then

strReason3KeyLi st = strReason3KeyLi st.Remove(strRe ason3KeyList.Le ngth - 1, 1)

strSql += "Update Provider set EnrolledReasonI D = 3 where PROVKEY in (" & strReason3KeyLi st & ") and customerid = '" & mstrCustomerID & "';"

End If

If strReason4KeyLi st.Length > 0 Then

strReason4KeyLi st = strReason4KeyLi st.Remove(strRe ason4KeyList.Le ngth - 1, 1)

strSql += "Update Provider set EnrolledReasonI D = 4 where PROVKEY in (" & strReason4KeyLi st & ") and customerid = '" & mstrCustomerID & "';"

End If

'instantiate the DAL

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

Try

'run the query

objDAL.RundsnBS GSystemSQL(strS ql)

Catch e As Exception

Throw New ApplicationExce ption(e.ToStrin g)

Finally

'release any objects

If Not objDAL Is Nothing Then

Runtime.Interop Services.Marsha l.ReleaseComObj ect(objDAL)

End If

End Try

'requery the database and rebind the grid

Call GetAllData()

If mintNumItems > 0 Then

Call BindGrid()

End If

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: Form_Submit()

'Description:

'Returns: Nothing

'History:

' 04-25-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Protected Sub Form_Submit(ByV al sender As Object, ByVal e As EventArgs)

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

'reset the current pagenumber

ViewState("Page Number") = 1

mintPageNumber = ViewState("Page Number")

Call GetAllData()

If mintNumItems > 0 Then

Call BindGrid()

Call LoadJumpToCombo ()

Else

lblMessage.Visi ble = True

lblMessage.Text = "No records found."

End If

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: GetAllData

'Description:

'Returns: Nothing

'History:

' 04-25-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub GetAllData(Opti onal ByVal strCustomerID As String = "", _

Optional ByVal strProvKey As String = "", _

Optional ByRef intKeyPage As Integer = 0)

Dim strSql As String, strWhereClause As String = ""

Dim objDAL As Object

Dim objRS As ADODB.Recordset

'if we didn't pass it in get the customerID from the Request object

If Len(strCustomer ID) = 0 Then

mstrCustomerID = Request.Form("t xtCustomerID")

End If

'Build the where clause, if any

If Len(Request.For m("txtPayerID") ) Then

strWhereClause += " AND p.PayerID = '" & Request.Form("t xtPayerID") & "'"

End If

If Len(Request.Que ryString("speci d")) Then

strWhereClause += " AND p.SpecID = '" & Request.QuerySt ring("specid") & "'"

ElseIf Len(Request.For m("cboCustSpec" )) And Request.Form("c boCustSpec") <> "ALL" Then

strWhereClause += " AND p.SpecID = '" & Request.Form("c boCustSpec") & "'"

End If

If Len(Request.For m("cboEnrolled" )) Then

strWhereClause += " AND p.Enrolled = '" & Request.Form("c boEnrolled") & "'"

End If

'instantiate the DAL

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

'If ordering by last name, add first name and middle initial to the query

If mstrOrderBy = "PROV_LAST" Then

mstrOrderBy = "PROV_LAST " & mstrOrderDir & ", PROV_FIRST " & mstrOrderDir & ", PROV_MI"

End If

'if ordering by anything other than name, append name to the order by clause

If mstrOrderBy <> "PROV_LAST " & mstrOrderDir & ", PROV_FIRST " & mstrOrderDir & ", PROV_MI" And mstrOrderBy <> "PROV_LAST" Then

mstrOrderBy += " " & mstrOrderDir & ", PROV_LAST " & mstrOrderDir & ", PROV_FIRST " & mstrOrderDir & ", PROV_MI"

End If

Try

objRS = objDAL.GetProvi derInfo(mstrCus tomerID, mstrOrderBy, mstrOrderDir, strWhereClause)

'This section here is used to get the pagenumber of a provider to mark as editable if we

'came here from the Search Provider screen.

strProvKey = "{" & strProvKey & "}"

Do While Not objRS.EOF

If objRS.Fields("N UM").Value = strProvKey.ToUp per Then

Exit Do

End If

intKeyPage += 1

objRS.MoveNext( )

Loop

'divide the index by the number of items per page to get the page no.

Dim dblTemp As Double

dblTemp = intKeyPage / RECORDSPERPAGE

'round down to the nearest whole number

intKeyPage = Math.Floor(dblT emp)

intKeyPage += 1

'get the number of items

mintNumItems = objRS.RecordCou nt

ViewState("Item Count") = mintNumItems

'Save the pagination info

fobjState.Creat ePaginationList (objRS)

'save the session

fobjState.SaveS ession()

Catch ex As Exception

Throw New ApplicationExce ption(ex.ToStri ng)

Finally

If Not objDAL Is Nothing Then

'release the DAL

System.Runtime. InteropServices .Marshal.Releas eComObject(objD AL)

End If

End Try

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: BindGrid()

'Description: Retrieves the current pages' recordset from the WUSMAP. The recordset is retrieved as an

' ADO recordset, then is converted to a dataset so it can be bound to the datagrid.

'Returns: Nothing

'History:

' 04-25-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub BindGrid()

Dim dsTemp As DataSet = New DataSet()

Dim odaTemp As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter()

Dim objRS As ADODB.Recordset

'first default all nav buttons to enabled

cmdFirst.Enable d = True

cmdNext.Enabled = True

cmdPrev.Enabled = True

cmdLast.Enabled = True

'make sure these are blank before we repopulate them

mstrJumpToOptio n = ""

mstrJumpToOptio nText = ""

Try

'if we are sorted by a combination of first-middle-last, use only last name to build the drop down list

If mstrOrderBy = "PROV_LAST " & mstrOrderDir & ", PROV_FIRST " & mstrOrderDir & ", PROV_MI" Then

mstrOrderBy = "PROV_LAST"

End If

'if the sort field is a combo of a field and then first-middle-last, remove the first-middle-last

'string from the end of the sort field

Dim strRemoveText As String = " " & mstrOrderDir & ", PROV_LAST " & mstrOrderDir & ", PROV_FIRST " & mstrOrderDir & ", PROV_MI"

If mstrOrderBy.Ind exOf(strRemoveT ext) > 0 Then

mstrOrderBy = mstrOrderBy.Rem ove(mstrOrderBy .IndexOf(strRem oveText), strRemoveText.L ength)

End If

'get the pagination info from the WUSMAP

objRS = fobjState.GetPa ginationRS(RECO RDSPERPAGE, mintPageNumber, mintFirstOnPage , mintNumPages, mintNumItems, _

mstrJumpToOptio n, mstrJumpToOptio nText, mstrItemList, mstrOrderBy)

'get the number of records on this page, only needed in case we delete all items on the last page to

'adjust the page number accordingly

mintItemsOnPage = objRS.RecordCou nt

'disable the nav button as appropriate

If mintPageNumber = mintNumPages Then

cmdLast.Enabled = False

cmdNext.Enabled = False

End If

If mintPageNumber = 1 Then

cmdFirst.Enable d = False

cmdPrev.Enabled = False

End If

'use the OLEDbDataAdapte r to fill the ADO recordset from the ADO.NET dataset.

odaTemp.Fill(ds Temp, objRS, "Provdata")

'ensure the data controls are visible

tblNav.Visible = True

dgProvUpdate.Vi sible = True

'bind the grid

dgProvUpdate.Da taSource = dsTemp

dgProvUpdate.Da taBind()

Catch e As Exception

Throw New ApplicationExce ption(e.ToStrin g)

Finally

'release any objects

odaTemp.Dispose ()

dsTemp.Dispose( )

If Not objRS Is Nothing Then

System.Runtime. InteropServices .Marshal.Releas eComObject(objR S)

End If

End Try

'update the pagecount from WUSMAP

ViewState("Page Count") = mintNumPages

End Sub

' -----------------------------------------------------------------------------

' Function Name: TaxIDType()

' Description: Function used to retrieve the tax ID's. Called when the

' user edits a row in the datagrid and populates the cboTaxIDType

' with the available types. Tax ID types are returned in the form

' of an ADO.NET data table.

' Returns: ADO.NET DataTable

' -----------------------------------------------------------------------------

Public Function TaxIDType() As DataTable

Dim dtTemp As DataTable = New DataTable()

Dim dcTemp As DataColumn = New DataColumn()

Dim drTemp As DataRow

'Create and add the columns to the datatable

dcTemp.ColumnNa me = "TAX_ID_VAL "

dtTemp.Columns. Add(dcTemp)

dcTemp = New DataColumn()

dcTemp.ColumnNa me = "TAX_ID_NAM E"

dtTemp.Columns. Add(dcTemp)

'create and add the rows to the datatable

drTemp = dtTemp.NewRow()

drTemp("TAX_ID_ VAL") = ""

drTemp("TAX_ID_ NAME") = ""

dtTemp.Rows.Add (drTemp)

drTemp = dtTemp.NewRow()

drTemp("TAX_ID_ VAL") = "E"

drTemp("TAX_ID_ NAME") = "EIN"

dtTemp.Rows.Add (drTemp)

drTemp = dtTemp.NewRow()

drTemp("TAX_ID_ VAL") = "S"

drTemp("TAX_ID_ NAME") = "SSN"

dtTemp.Rows.Add (drTemp)

'return the temporary table

Return dtTemp

End Function

' -----------------------------------------------------------------------------

' Function Name: GetReasonCode()

' Description: Function used to retrieve the enrolled/unenrolled reason codes.

' Called when the user edits a row in the datagrid and populates

' the cboReasonCode with the available types.

' Returns: ADO.NET DataTable

' -----------------------------------------------------------------------------

Public Function GetReasonCode() As DataTable

Dim strSql As String

Dim objDAL As Object

Dim objRS As ADODB.Recordset

'get the customerID from the Request object

mstrCustomerID = Request.Form("t xtCustomerID")

'if it wasn't in the form, it may be in the querystring if we came from the search screen

If Len(mstrCustome rID) = 0 Then

mstrCustomerID = Request.QuerySt ring("customeri d")

End If

'build the sql

strSql = "Select * from EnrolledReason"

'instantiate the DAL

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

objRS = objDAL.RundsnBS GSystemSQLRetur nRS(strSql)

'create the ADO.NET objects

Dim dt As DataTable = New DataTable()

Dim oda As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter()

'Fill the DataTable with the recordset data

oda.Fill(dt, objRS)

'return the DataTable

Return dt

End Function

' -----------------------------------------------------------------------------

' Function Name: GetSpec()

' Description: Function used to retrieve the specs.

' Called when the user edits a row in the datagrid and populates

' the cboReasonCode with the available types.

' Returns: ADO.NET DataTable

' -----------------------------------------------------------------------------

Public Function GetSpec() As DataTable

Dim strSql As String

Dim objDAL As Object

Dim objRS As ADODB.Recordset

objRS = GetSpecData()

'create the ADO.NET objects

Dim dt As DataTable = New DataTable()

Dim oda As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter()

'Fill the DataTable with the recordset data

oda.Fill(dt, objRS)

'return the DataTable

Return dt

End Function

' -----------------------------------------------------------------------------

' Function Name: GetSpecData

' Description: Sub Routine to run page specific logic

' -----------------------------------------------------------------------------

Protected Function GetSpecData() As ADODB.Recordset

Dim strSql As String = ""

Dim objDAL As Object

Dim objRS As ADODB.Recordset

'get the customerID from the Request object

mstrCustomerID = Request.Form("t xtCustomerID")

'if it wasn't in the form, it may be in the querystring if we came from the search screen

If Len(mstrCustome rID) = 0 Then

mstrCustomerID = Request.QuerySt ring("customeri d")

End If

'build the sql statement

strSql = "Select c.specid as specid,s.specna me as specname " & _

"from CUSTSPEC c INNER JOIN SpcIDRef s on c.specid = s.specid where customerid='" & mstrCustomerID & _

"' and s.specid not in (select unknownspecid from formtypeinfo) order by s.specname"

Try

'instantiate the DAL

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

objRS = objDAL.RundsnBS GSystemSQLRetur nRS(strSql)

'if there were no records check in Local

If objRS.RecordCou nt = 0 Then

strSql = "Select c.specid,s.spec name,s.spec_ass ign_id,s.spec_a ssign_id2,s.Pro vTablePayerIDRe q " & _

"from CUSTSPEC c INNER JOIN dsnBSGSystem.db o.SpcIDRef s on c.specid = s.specid where customerid='" & mstrCustomerID & _

"' and s.specid not in (select unknownspecid from dsnBSGSystem.db o.formtypeinfo) order by s.specname"

Runtime.Interop Services.Marsha l.ReleaseComObj ect(objDAL)

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

'run the sql

objRS = objDAL.RundsnBS GSystemSQLRetur nRS(strSql)

End If

'return the recordset

Return objRS

objRS.ActiveCon nection = Nothing

Catch ex As Exception

Throw New ApplicationExce ption(ex.ToStri ng)

Finally

'release any objects

If Not objDAL Is Nothing Then

Runtime.Interop Services.Marsha l.ReleaseComObj ect(objDAL)

End If

End Try

End Function

' -----------------------------------------------------------------------------

' Function Name: LoadCustSpecCom bo()

' Description: Called to load the Cust Spec drop down list with LOBs

' -----------------------------------------------------------------------------

Protected Sub LoadCustSpecCom bo()

Dim objRS As ADODB.Recordset

'call GetSpecData to get a recordset of LOBs

objRS = GetSpecData()

'clear out the drop down so we don't have any dupes

cboCustSpec.Ite ms.Clear()

cboCustSpec.Ite ms.Add(New ListItem("ALL", "ALL"))

'loop through the recordset and add items to the CustSpec drop down

Do While Not objRS.EOF

cboCustSpec.Ite ms.Add(New ListItem(objRS. Fields("specnam e").Value, objRS.Fields("s pecid").Value))

objRS.MoveNext( )

Loop

End Sub

' -----------------------------------------------------------------------------

' Function Name: PrePageDisplayL ogic

' Description: Sub Routine to run page specific logic

' -----------------------------------------------------------------------------

Protected Overrides Sub PrePageDisplayL ogic()

Try

'set the objects fields for the current page

fstrPageTitle = "Update Provider"

fstrPageName = "UpdateProvider "

fblnPrint = False

fblnShowMenu = True

'DNR. The base class will need these objects

flitHeadHeader = litHeadHeader

flitHeadFooter = litHeadFooter

Catch

RaisePageError( Err, "PageDisplayLog ic")

End Try

End Sub

' -----------------------------------------------------------------------------

' Function Name: dgProvUpdate_Ed itCommand()

' Description: Event fired when an item in the datagrid is bound to it's

' datasource.

' -----------------------------------------------------------------------------

Private Sub dgProvUpdate_Ed itCommand(ByVal sender As Object, ByVal e As DataGridCommand EventArgs) Handles dgProvUpdate.Ed itCommand

'this tells the datagrid to render one row (the selected one) as editable fields

dgProvUpdate.Ed itItemIndex = e.Item.ItemInde x

'Get the TaxID Type so we can use it to preselect the correct choice in the TaxIDType dropdown

ViewState("TaxI DType") = UCase(CType(e.I tem.FindControl ("lblTaxIDType" ), Label).Text)

ViewState("Spec ID") = UCase(CType(e.I tem.FindControl ("SPECID"), Label).Text)

ViewState("Enro lledReason") = CType(e.Item.Fi ndControl("cboE nrolledReason") , DropDownList).S electedItem.Val ue

're-bind the grid

Call BindGrid()

hfnAction.Value = "SetFocus_" & e.Item.ItemInde x

End Sub

' -----------------------------------------------------------------------------

' Function Name: DeleteProvider( )

' Description: Called when one or more items in the datagrid are marked for deletion.

' -----------------------------------------------------------------------------

Private Sub DeleteProvider( )

Dim strSql As String, strProvKey As String, strDeleteList As String

Dim objDAL As Object

Dim rsDeleteList As ADODB.Recordset

Dim dgiTemp As DataGridItem

Dim chkTemp As CheckBox

'get the relevant provkey value

For Each dgiTemp In dgProvUpdate.It ems

chkTemp = CType(dgiTemp.F indControl("chk Delete"), CheckBox)

If chkTemp.Checked = True Then

strProvKey += CType(dgiTemp.F indControl("NUM "), Label).Text & ","

End If

Next

'LOP off the last comma and insert the single quotes for the IN clause

strProvKey = strProvKey.Remo ve(strProvKey.L ength - 1, 1)

strProvKey = strProvKey.Repl ace(",", "','")

Try

'instantiate the DAL

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

'get a recordset of prov_id's to be deleted

strSql = "SELECT 'Provider[' + PROV_ID + '];SpecID[' + Str(SPECID,3) + ']' from provider WHERE PROVKEY IN ('" & strProvKey & "')"

rsDeleteList = objDAL.RundsnBS GSystemSQLRetur nRS(strSql)

'create a comma-delimited list of provider info

strDeleteList = rsDeleteList.Ge tString(ADODB.S tringFormatEnum .adClipString, , " ", ",")

strDeleteList = Left(strDeleteL ist, Len(strDeleteLi st) - 1)

rsDeleteList.Cl ose()

'delete the providers

strSql = "DELETE From Provider Where PROVKEY in ('" & strProvKey & "')"

objDAL.RundsnBS GSystemSQL(strS ql)

'make an entry into tracklog

AddTrackLog(Req uest.Form("txtC ustomerID"), " deleted " & strDeleteList & " for " & Request.Form("t xtCustomerID") & ".", "UpdateProvider .aspx")

Catch ex As Exception

Throw New ApplicationExce ption(ex.ToStri ng)

Finally

If Not objDAL Is Nothing Then

'release the DAL

System.Runtime. InteropServices .Marshal.Releas eComObject(objD AL)

End If

End Try

'requery the database

Call GetAllData()

If mintNumItems > 0 Then

'if there are items remaining, re-bind the datagrid

Call BindGrid()

Call LoadJumpToCombo ()

Else

'if the last item has been deleted, notify the user and hide the datagrid and nav controls.

lblMessage.Visi ble = True

lblMessage.Text = "No records found."

dgProvUpdate.Vi sible = False

tblNav.Visible = False

End If

End Sub

' -----------------------------------------------------------------------------

' Function Name: dgProvUpdate_Ca ncelCommand()

' Description: Event fired when an item in the datagrid is bound to it's

' datasource.

' -----------------------------------------------------------------------------

Private Sub dgProvUpdate_Ca ncelCommand(ByV al sender As Object, ByVal e As DataGridCommand EventArgs) Handles dgProvUpdate.Ca ncelCommand

'setting EditItemIndex = -1 sets all rows back to non editable

dgProvUpdate.Ed itItemIndex = -1

Call BindGrid()

End Sub

' -----------------------------------------------------------------------------

' Function Name: dgProvUpdate_Up dateCommand()

' Description: Event fired when an editable item in the datagrid is updated

' -----------------------------------------------------------------------------

Private Sub dgProvUpdate_Up dateCommand(ByV al sender As Object, ByVal e As DataGridCommand EventArgs) Handles dgProvUpdate.Up dateCommand

Dim strProvKey As String, strSql As String, strSpecID As String, strProvID As String, strProvGroupNo As String, _

strProvLast As String, strProvFirst As String, strProvMI As String, strProvName As String, strProvTaxID As String, _

strProvTaxIDTyp e As String, strSpecAssignID As String, strSpecAssignID 2 As String, strBatch As String, _

strPayerID As String, strEnrolled As String, strEnrolledReas onID As String

Dim objRS As ADODB.Recordset

Dim objDAL As Object

Try

'get all the values from the datagrid

strProvKey = Trim$(UCase(CTy pe(e.Item.FindC ontrol("NUM"), Label).Text))

strSpecID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("cboSpec "), DropDownList).S electedItem.Val ue))

strProvID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_ID "), TextBox).Text))

strProvGroupNo = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_GR OUPNO"), TextBox).Text))

strProvLast = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_LA ST"), TextBox).Text))

strProvFirst = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_FI RST"), TextBox).Text))

strProvMI = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_MI "), TextBox).Text))

strProvName = Trim$(UCase(CTy pe(e.Item.FindC ontrol("SITENAM E"), Label).Text))

strProvTaxID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_TA XID"), TextBox).Text))

strProvTaxIDTyp e = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PROV_TA XID_TYPE"), DropDownList).S electedItem.Val ue))

strSpecAssignID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("SPEC_AS SIGN_ID"), TextBox).Text))

strSpecAssignID 2 = Trim$(UCase(CTy pe(e.Item.FindC ontrol("SPEC_AS SIGN_ID2"), TextBox).Text))

strBatch = Trim$(UCase(CTy pe(e.Item.FindC ontrol("NSFBatc hing"), TextBox).Text))

strPayerID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("PAYERID "), TextBox).Text))

If CType(e.Item.Fi ndControl("chkE nroll"), CheckBox).Check ed = True Then

strEnrolled = "Y"

Else

strEnrolled = "N"

End If

'if Enrolled is Yes then default the reason to "Enrolled"

If strEnrolled = "Y" Then

strEnrolledReas onID = "1"

Else

strEnrolledReas onID = Trim$(UCase(CTy pe(e.Item.FindC ontrol("cboEnro lledReason"), DropDownList).S electedItem.Val ue))

End If

'build the sql, if fields are blank then set the value to NULL

strSql = "UPDATE Provider set "

If strSpecID.Lengt h = 0 Then

strSql += "SPECID = NULL, "

Else

strSql += "SPECID = '" & strSpecID & "', "

End If

If strProvID.Lengt h = 0 Then

strSql += "PROV_ID = NULL, "

Else

strSql += "PROV_ID = '" & strProvID & "', "

End If

If strProvGroupNo. Length = 0 Then

strSql += "PROV_GROUP NO = NULL, "

Else

strSql += "PROV_GROUP NO = '" & strProvGroupNo & "', "

End If

If strProvLast.Len gth = 0 Then

strSql += "PROV_LAST = NULL, "

Else

If strProvLast.Ind exOf("'") > -1 Then

strProvLast = strProvLast.Rep lace("'", "''")

End If

strSql += "PROV_LAST = '" & strProvLast & "', "

End If

If strProvFirst.Le ngth = 0 Then

strSql += "PROV_FIRST = NULL, "

Else

If strProvFirst.In dexOf("'") > -1 Then

strProvFirst = strProvFirst.Re place("'", "''")

End If

strSql += "PROV_FIRST = '" & strProvFirst & "', "

End If

If strProvMI.Lengt h = 0 Then

strSql += "PROV_MI = NULL, "

Else

strSql += "PROV_MI = '" & strProvMI & "', "

End If

If strProvName.Len gth = 0 Then

strSql += "PROV_NAME = NULL, "

Else

If strProvName.Ind exOf("'") > -1 Then

strProvName = strProvName.Rep lace("'", "''")

End If

strSql += "PROV_NAME = '" & strProvName & "', "

End If

If strProvTaxID.Le ngth = 0 Then

strSql += "PROV_TAXID = NULL, "

Else

strSql += "PROV_TAXID = '" & strProvTaxID & "', "

End If

If strProvTaxIDTyp e.Length = 0 Then

strSql += "PROV_TAXID_TYP E = NULL, "

Else

strSql += "PROV_TAXID_TYP E = '" & strProvTaxIDTyp e & "', "

End If

If strSpecAssignID .Length = 0 Then

strSql += "SPEC_ASSIG N_ID = NULL, "

Else

strSql += "SPEC_ASSIG N_ID = '" & strSpecAssignID & "', "

End If

If strSpecAssignID 2.Length = 0 Then

strSql += "SPEC_ASSIGN_ID 2 = NULL, "

Else

strSql += "SPEC_ASSIGN_ID 2 = '" & strSpecAssignID 2 & "', "

End If

If strBatch.Length = 0 Then

strSql += "NSFBatchin g = NULL, "

Else

strSql += "NSFBatchin g = '" & strBatch & "', "

End If

If strPayerID.Leng th = 0 Then

strSql += "PAYERID = NULL, "

Else

strSql += "PAYERID = '" & strPayerID & "', "

End If

If strEnrolled.Len gth = 0 Then

strSql += "ENROLLED = NULL, "

Else

strSql += "ENROLLED = '" & strEnrolled & "', "

End If

If strEnrolledReas onID.Length = 0 Then

strSql += "EnrolledReason ID = NULL, "

Else

strSql += "EnrolledReason ID = '" & strEnrolledReas onID & "', "

End If

strSql = strSql.Remove(s trSql.Length - 2, 1)

strSql += " WHERE PROVKEY = '" & strProvKey & "'"

objDAL = CreateObject("P ayerpathDAL.dsn BSGSystem")

objDAL.rundsnBS GSystemSQL(strS ql)

'make an entry into tracklog

AddTrackLog(Req uest.Form("txtC ustomerID"), " updated provider [" & strProvFirst & " " & strProvMI & _

" " & strProvLast & ": " & strProvID & "] for " & Request.Form("t xtCustomerID") & ".", "UpdateProvider .aspx")

'reset the rows to non-editable

dgProvUpdate.Ed itItemIndex = -1

Catch ex As Exception

Throw New ApplicationExce ption(ex.ToStri ng())

Finally

Runtime.Interop Services.Marsha l.ReleaseComObj ect(objDAL)

End Try

'Re-query the database and re-bind the datagrid

Call GetAllData()

If mintNumItems > 0 Then

'if there are items remaining, re-bind the datagrid

Call BindGrid()

Call LoadJumpToCombo ()

Else

'if the last item has been deleted, notify the user and hide the datagrid and nav controls.

lblMessage.Visi ble = True

lblMessage.Text = "No records found."

dgProvUpdate.Vi sible = False

tblNav.Visible = False

End If

End Sub

' -----------------------------------------------------------------------------

' Function Name: dgProvUpdate_It emDataBound()

' Description: Event fired when an item in the datagrid is bound to it's

' datasource.

' -----------------------------------------------------------------------------

Private Sub dgProvUpdate_It emDataBound(ByV al sender As Object, ByVal e As DataGridItemEve ntArgs) Handles dgProvUpdate.It emDataBound

Dim cboTemp As DropDownList

'When an item is edited (ListItemType.E ditItem) preselect the value of the TaxIDType drop down

'based on the value of the PROV_TAXID_TYPE field (ViewState("Tax IDType"))

If e.Item.ItemType = ListItemType.Ed itItem Then

cboTemp = CType(e.Item.Fi ndControl("PROV _TAXID_TYPE"), DropDownList)

cboTemp.Selecte dIndex = cboTemp.Items.I ndexOf(cboTemp. Items.FindByVal ue(ViewState("T axIDType")))

cboTemp = CType(e.Item.Fi ndControl("cboS PEC"), DropDownList)

cboTemp.Selecte dIndex = cboTemp.Items.I ndexOf(cboTemp. Items.FindByVal ue(ViewState("S pecID")))

cboTemp = CType(e.Item.Fi ndControl("cboE nrolledReason") , DropDownList)

cboTemp.Selecte dIndex = cboTemp.Items.I ndexOf(cboTemp. Items.FindByVal ue(ViewState("E nrolledReason") ))

End If

'when each row is drawn, find the checkbox. If the value of the ENROLLED field (lblEnrolled) is

'"Y", then check the checkbox

If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType = ListItemType.Al ternatingItem Or e.Item.ItemType = ListItemType.Ed itItem Then

Dim chkTemp As CheckBox

'get the value of the ENROLLED field indicated by lblEnrolled

ViewState("Enro lled") = UCase(CType(e.I tem.FindControl ("lblEnrolled") , Label).Text)

'get a reference to the current chkEnroll checkbox

chkTemp = CType(e.Item.Fi ndControl("chkE nroll"), CheckBox)

'check the checkbox if appropriate

If ViewState("Enro lled") = "Y" Then

chkTemp.Checked = True

Else

chkTemp.Checked = False

End If

'Find the enrolled reason dropdown. Get the reason code (from lblReasonID) and preselect it in the dropdown.

ViewState("Enro lledReason") = CInt(UCase(CTyp e(e.Item.FindCo ntrol("lblReaso nID"), Label).Text))

'get a reference to the dropdown

cboTemp = CType(e.Item.Fi ndControl("cboE nrolledReason") , DropDownList)

cboTemp.Selecte dIndex = ViewState("Enro lledReason") - 1

End If

End Sub

' -----------------------------------------------------------------------------

' Function Name: dgProvUpdate_It emCreated()

' Description: Event fired when a datagrid item is created

' -----------------------------------------------------------------------------

Public Sub dgProvUpdate_It emCreated(ByVal sender As Object, ByVal e As DataGridItemEve ntArgs) Handles dgProvUpdate.It emCreated

Dim strTemp As String

Dim tcTemp As TableCell = New TableCell()

Dim dgiTemp As DataGridItem

Dim lnkTemp As LinkButton

dgiTemp = e.Item

tcTemp = CType(dgiTemp.C ontrols(0), TableCell)

If e.Item.ItemType = ListItemType.Ed itItem Then

lnkTemp = tcTemp.Controls (0)

lnkTemp.Attribu tes.Add("onclic k", "javascript:if( ValidateReason( " & e.Item.ItemInde x & ")){return true;}else{retu rn false;}")

End If

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: SortGrid()

'Description: Event handler for the DataGridOnSortC ommand event. Determines the direction of the sort,

' sets the sort field, and then calls GetAllData, BindGrid, and LoadJumpToCombo to requery

' the database and refresh the grid and drop down.

'History:

' 02-06-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Protected Sub SortGrid(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Data GridSortCommand EventArgs) Handles dgProvUpdate.So rtCommand

mstrOrderBy = e.SortExpressio n

'toggle the sort order

If mstrOrderBy = ViewState("Sort Field") Then

If mstrOrderDir = "ASC" Then

mstrOrderDir = "DESC"

Else

mstrOrderDir = "ASC"

End If

Else

mstrOrderDir = "ASC"

End If

ViewState("Sort Field") = mstrOrderBy

ViewState("Sort Direction") = mstrOrderDir

'requery the database, rebind the grid, and repopulate the jump to combo

Call GetAllData()

If mintNumItems > 0 Then

Call BindGrid()

Call LoadJumpToCombo ()

End If

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: cmdNext_Click()

'Description: Handles the click event for the cmdNext linkbutton.

'History:

' 04-28-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub cmdNext_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdNext.Click

'increment the page num by 1

ViewState("Page Number") = mintPageNumber + 1

mintPageNumber = ViewState("Page Number")

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

'rebind the grid

Call BindGrid()

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: cmdPrev_Click()

'Description: Handles the click event for the cmdPrev linkbutton.

'History:

' 04-28-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub cmdPrev_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdPrev.Click

'decrement the page num by 1

ViewState("Page Number") = mintPageNumber - 1

mintPageNumber = ViewState("Page Number")

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

'rebind the grid

Call BindGrid()

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: cmdLast_Click()

'Description: Handles the click event for the cmdLast linkbutton.

'History:

' 04-28-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub cmdLast_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles cmdLast.Click

'we're going to the last page, so the pagenum should equal the page count

mintPageNumber = ViewState("Page Count")

ViewState("Page Number") = mintPageNumber

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

'rebind the grid

Call BindGrid()

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: cmdFirst_Click( )

'Description: Handles the click event for the cmdFirst linkbutton. Updates the page number and calls

' BindGrid to refresh the data.

'History:

' 04-28-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Private Sub cmdFirst_Click( ByVal sender As Object, ByVal e As System.EventArg s) Handles cmdFirst.Click

'set the page num = to the first page

mintPageNumber = 1

ViewState("Page Number") = 1

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

'rebind the grid

Call BindGrid()

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: LoadJumpToCombo ()

'Description:

'History:

' 04-28-03 JK - Created new

'-----------------------------------------------------------------------------------------------------------

Public Sub LoadJumpToCombo ()

Dim intIndex As Integer, intIndex2 As Integer

cboPage.Items.C lear()

'populate the drop down

intIndex = 1

Try

Do While intIndex > 0

intIndex = mstrJumpToOptio n.IndexOfAny(", ")

intIndex2 = mstrJumpToOptio nText.IndexOfAn y(",")

'parse the strings (comma-delimited) of names and values and add them

'ex. 200102031500,20 0102031501,2001 02031502

'if the intIndex < 0, i.e -1, then there is only one item. Add it, and since the value is

'-1, the loop will exit

If intIndex < 0 Then

cboPage.Items.A dd(New ListItem(mstrJu mpToOptionText, mstrJumpToOptio n))

'if the intIndex is > 0, then there are multiple items. Add the current item, and loop

'back around for more, until intIndex = -1

Else

cboPage.Items.A dd(New ListItem(mstrJu mpToOptionText. Substring(0, _

mstrJumpToOptio nText.Length - (mstrJumpToOpti onText.Length - intIndex2)), _

mstrJumpToOptio n.Substring(0, mstrJumpToOptio n.Length - (mstrJumpToOpti on.Length - intIndex))))

End If

'lop the item we just added to the drop down off of the end of the string

mstrJumpToOptio n = mstrJumpToOptio n.Remove(0, intIndex + 1)

mstrJumpToOptio nText = mstrJumpToOptio nText.Remove(0, intIndex2 + 1)

Loop

cboPage.Items(m intPageNumber - 1).Selected = True

'change the page's action to SpecChanged

hfnAction.Value = "SpecChange d"

Catch ex As Exception

Throw New ApplicationExce ption(ex.ToStri ng())

End Try

End Sub

'-----------------------------------------------------------------------------------------------------------

'Function Name: cboPage_Selecte dIndexChanged()

'Description: Handles the SelectedIndexCh anged event for the cboPage dropdownlist.

'History:

' 05-01-03 JK - Created New

'-----------------------------------------------------------------------------------------------------------

Sub cboPage_Selecte dIndexChanged(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cboPage.Selecte dIndexChanged

'set the pagenumber to the selected index of the jump to combo

ViewState("Page Number") = cboPage.Selecte dItem.Value

mintPageNumber = ViewState("Page Number")

'rebind the grid

Call BindGrid()

'if a provider was marked for updating and the user shifted gears, reset the edititemindex to -1

dgProvUpdate.Ed itItemIndex = -1

End Sub

End Class

"Teemu Keiski" <jo****@aspalli ance.com> wrote in message news:Oo******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

it is hard to say without seeing your code. Post the relevant code.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
"John Kirksey" <jo**********@v erizon.net> wrote in message news:Oi******** ********@TK2MSF TNGP12.phx.gbl. ..
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid.

Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message of "No records found" which is correct, because my filter is still looking for no. NOW, if I then resubmit the form, I get the following error:

System.Web.Http Exception: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.C ontrol.LoadView StateRecursive( Object savedState)
at System.Web.UI.P age.LoadPageVie wState()
at System.Web.UI.P age.ProcessRequ estMain()
--- End of inner exception stack trace ---
at System.Web.UI.P age.HandleError (Exception e)
at System.Web.UI.P age.ProcessRequ estMain()
at System.Web.UI.P age.ProcessRequ est()
at System.Web.Util .AspCompatAppli cationStep.Syst em.Web.HttpAppl ication+IExecut ionStep.Execute ()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean& completedSynchr onously)

The only way to not get this error is to reload the page completely.

What could be my problem??

Thanks in advance,

John Kirksey


Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3000
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed to load viewstate" error. This happens on Windows Server 2003. It happens erratically, and appears to happen after the application has been running (and in use) for some time. When the problem arises, it appears to happen more frequently for a...
0
2582
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a usercontrol into the place holder... i dont know why im getting this error:
1
6645
by: et | last post by:
I. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. Description: An unhandled exception occurred during the execution of the current web...
1
2252
by: rockdale | last post by:
Sometime my ASP.NET application got this error message but not always everytime. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request
6
2940
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page has expired instead of getting the error? Thanks,
2
4513
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
1
3318
by: j-in-uk | last post by:
I have linkButtons on my page, onclick of the link button I want to load the proper usercontrol, this works fine the 1st time I click but when I click the 2nd linkButton I get "Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must...
0
1663
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the item which was selected in the previous run the following error message is displayed.. Please help me in this regard.. Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to...
2
11007
by: Rotsey | last post by:
Hi, I have a web site that uses user controls to display different formats of timesheets. I have a browse page that has prev/next buttons to browse through a set of timesheets. As I say they can be different user controls for each timesheet type.
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10749
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7133
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5801
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5994
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3236
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.