Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2nd call to form doesn't work 1

Status
Not open for further replies.

whateveragain

Programmer
Apr 20, 2009
92
US
I call formA which displays a table. FormA calls another formB, which allows me to make selections that calls 2 SPs and alters the table displayed in formA. When in formB, focus is no longer on formA. The changes in the tables are made correctly, but the original table still displays when I call it again from formB. What is wrong? I had posted a similar question earlier, but the SP wasn't entered a 2nd time in order to re-process the changes. Now, it does work, but the form doesn't on the 2nd call.
 
Jason responsed to your original post and made a valid point: If you want the proper help, you need to post the relevant code. Also, your process does seem overly complex. If you explain what you are trying to do, we could possibly suggest a better apporoach.

Based on what you wrote, I would first look at where you are retreiving the data. Are you calling the SP a second time, or is it wrapped in an if(!page.ispostback) block? What control are you displaying the data in? Did you turn off Viewstate on that control?
 
Are you calling the SP a second time, or is it wrapped in an if(!page.ispostback) block? No

What control are you displaying the data in? datagrid

Did you turn off Viewstate on that control? This may be my problem, I'm reading about viewstate as I wait for a reply. Currently, I don't know how to turn off/on viewstate.

1st working call:
Protected Sub statecond()
myID = Session.SessionID()
tempstring = Session("tempstring")

Dim sqlConn As New SqlConnection
Dim sqlComm As New SqlCommand
Dim command As New SqlCommand()
getrank()
getok()

sqlComm.Connection = sqlConn
sqlConn.ConnectionString = Session("MyString")
sqlComm.CommandText = "statecond" '-- specifying the command text
sqlComm.CommandType = CommandType.StoredProcedure '-- specifying the command text is a stored proc

With sqlComm
.Parameters.Add("@MyId", SqlDbType.VarChar, 55, myID)
.Parameters.Add("@selpubs", SqlDbType.VarChar, 100, Session("selpubs"))
.Parameters.Add("@Rank2", SqlDbType.VarChar, 1, Rank2)
.Parameters.Add("@oktype", SqlDbType.VarChar, 40, oktype)
.Parameters.Add("@oktypeor", SqlDbType.VarChar, 40, oktypeor)
.Parameters.Add("@okcat", SqlDbType.VarChar, 40, okcat)
.Parameters.Add("@okcator", SqlDbType.VarChar, 40, okcator)
.Parameters.Add("@mgetfilter", SqlDbType.Int, 4, 1)

'-- specifying the parameter directions
.Parameters("@MyId").Direction = ParameterDirection.Input
.Parameters("@selpubs").Direction = ParameterDirection.Input
.Parameters("@Rank2").Direction = ParameterDirection.Input
.Parameters("@oktype").Direction = ParameterDirection.Input
.Parameters("@oktypeor").Direction = ParameterDirection.Input
.Parameters("@okcat").Direction = ParameterDirection.Input
.Parameters("@okcator").Direction = ParameterDirection.Input
.Parameters("@mgetfilter").Direction = ParameterDirection.Input

'-- assigning values to the parameters
.Parameters("@MyId").Value = myID
.Parameters("@selpubs").Value = Session("selpubs")
.Parameters("@Rank2").Value = Rank2
.Parameters("@oktype").Value = oktype
.Parameters("@oktypeor").Value = oktypeor
.Parameters("@okcat").Value = okcat
.Parameters("@okcator").Value = okcator
.Parameters("@mgetfilter").Value = 1
End With

'-- opening the connection
command.CommandTimeout = 0
sqlConn.Open()

sqlComm.Connection = sqlConn

sqlComm.ExecuteNonQuery()
'-- executing the command
'stCount = sqlComm.ExecuteScalar ' return value
'-- close the connection
sqlConn.Close()
End Sub


Call that doesn't work:
2nd call:
Sub statecond()
myID = Session.SessionID()
tempstring = Session("tempstring")

Dim sqlConn As New SqlConnection
Dim sqlComm As New SqlCommand
Dim command As New SqlCommand()
getrank()
getok()

sqlComm.Connection = sqlConn
sqlConn.ConnectionString = Session("MyString")

sqlComm.CommandText = "statecond" '-- specifying the command text
sqlComm.CommandType = CommandType.StoredProcedure '-- specifying the command text is a stored proc
With sqlComm

'-- adding the parameters
.Parameters.Add("@MyId", SqlDbType.VarChar, 55, myID)
.Parameters.Add("@selpubs", SqlDbType.VarChar, 100, Session("selpubs"))
.Parameters.Add("@Rank2", SqlDbType.VarChar, 1, rank2)
.Parameters.Add("@oktype", SqlDbType.VarChar, 40, oktype)
.Parameters.Add("@oktypeor", SqlDbType.VarChar, 40, oktypeor)
.Parameters.Add("@okcat", SqlDbType.VarChar, 40, okcat)
.Parameters.Add("@okcator", SqlDbType.VarChar, 40, okcator)
.Parameters.Add("@mgetfilter", SqlDbType.Int, 4, 1)

'-- specifying the parameter directions
.Parameters("@MyId").Direction = ParameterDirection.Input
.Parameters("@selpubs").Direction = ParameterDirection.Input
.Parameters("@Rank2").Direction = ParameterDirection.Input
.Parameters("@oktype").Direction = ParameterDirection.Input
.Parameters("@oktypeor").Direction = ParameterDirection.Input
.Parameters("@okcat").Direction = ParameterDirection.Input
.Parameters("@okcator").Direction = ParameterDirection.Input
.Parameters("@mgetfilter").Direction = ParameterDirection.Input

'-- assigning values to the parameters
.Parameters("@MyId").Value = myID
.Parameters("@selpubs").Value = Session("selpubs")
.Parameters("@Rank2").Value = rank2
.Parameters("@oktype").Value = oktype
.Parameters("@oktypeor").Value = oktypeor
.Parameters("@okcat").Value = okcat
.Parameters("@okcator").Value = okcator
.Parameters("@mgetfilter").Value = 1
End With

'-- opening the connection
sqlConn.Open()

sqlComm.Connection = sqlConn
sqlComm.ExecuteNonQuery()
'-- executing the command
'stCount = sqlComm.ExecuteScalar ' return value
'-- close the connection
sqlConn.Close()
End Sub
 
I found the enableviewstate property for the gridview and it is set to false.
 
I turned off the enable caching for the SqlDataSource and it works. It may not be the most effection method for bandwidth. If there's a better way, feel free to tell me.
 
SqlDataSource" that's part of the problem. data source controls are the one of the worst things about webforms. they are deceptively enticing to use. but they just cause more problems than they solve.

caching is the other problem. caching should be your last option to optimize a system. most of the time caching solves a symptom, not the problem. it's not to say caching is evil. it' a very powerful tool. i just see many devs jump straight to cache without considering why the process is slow or how to invalidate the cache.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top