Gridview does not refresh display updated record - asp.net

I am currently working on a project. I suddenly stumbled on a problem that really blew my brains. I have a function that displays the content of a table in a database to a gridview which I named bindGrid. It is working perfectly fine when I query 50 to 90 records. However when I query 100 records or more the gridview does not display the records until I change the value of my dropdown box that is set to autopostback.
Here is the sample of the code:
Protected Sub btnFilter_Click(sender As Object, e As EventArgs) Handles btnFilter.Click
If cboFilter.Text = "DMZ" Then
lblErrFilter.Visible = False
lblError.Visible = False
If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtDMZ.Text = "--Select--" Or txtTop.Text = "" Then
If drpYear.Text = "--Select--" Then
lblErrYear.Visible = True
Else
lblErrYear.Visible = False
End If
If drpMonth.Text = "--Select--" Then
lblErrMonth.Visible = True
Else
lblErrMonth.Visible = False
End If
If txtDMZ.Text = "--Select--" Then
lblErrDMZ.Visible = True
Else
lblErrDMZ.Visible = False
End If
lblError.Visible = True
lblError.Text = "No value specified for the following parameter(s) *."
Else
lblErrYear.Visible = False
lblErrMonth.Visible = False
lblErrDMZ.Visible = False
Call bindData()
'If Me.IsPostBack = True Then
Call bindGrid()
'End If
'
End If
'__________________________________________________________________________
'Zone filter
ElseIf cboFilter.Text = "Zone and Book" Then
lblErrFilter.Visible = False
lblError.Visible = False
If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtZone.Text = "--Select--" Or txtTop.Text = "" Then
If drpYear.Text = "--Select--" Then
lblErrYear.Visible = True
Else
lblErrYear.Visible = False
End If
If drpMonth.Text = "--Select--" Then
lblErrMonth.Visible = True
Else
lblErrMonth.Visible = False
End If
If txtZone.Text = "--Select--" Then
lblErrZone.Visible = True
Else
lblErrZone.Visible = False
End If
lblError.Visible = True
lblError.Text = "No value specified for the following parameter(s) *."
Else
lblErrYear.Visible = False
lblErrMonth.Visible = False
lblErrZone.Visible = False
Call bindData()
Call bindGrid()
End If
ElseIf cboFilter.Text = "Account Number" Then
If txtFrom.Visible = True And txtTo.Visible = True Then
If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtFrom.Text = "" Or txtTo.Text = "" Then
If drpYear.Text = "--Select--" Then
lblErrYear.Visible = True
Else
lblErrYear.Visible = False
End If
If drpMonth.Text = "--Select--" Then
lblErrMonth.Visible = True
Else
lblErrMonth.Visible = False
End If
If txtFrom.Text = "" Then
lblErrR1.Visible = True
Else
lblErrR1.Visible = False
End If
If txtTo.Text = "" Then
lblErrR2.Visible = True
Else
lblErrR2.Visible = False
End If
lblError.Visible = True
lblError.Text = "No value specified for the following parameter(s) *."
Else
Call bindData()
Call bindGrid()
End If
Else
If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or lstAcct.Items.Count = 0 Then
If drpYear.Text = "--Select--" Then
lblErrYear.Visible = True
Else
lblErrYear.Visible = False
End If
If drpMonth.Text = "--Select--" Then
lblErrMonth.Visible = True
Else
lblErrMonth.Visible = False
End If
If lstAcct.Items.Count = 0 Then
lblErrAcct.Visible = True
Else
lblErrAcct.Visible = False
End If
lblError.Visible = True
lblError.Text = "No value specified for the following parameter(s) *."
Else
lblErrYear.Visible = False
lblErrMonth.Visible = False
lblErrR1.Visible = False
lblErrR2.Visible = False
Call bindData()
Call bindGrid()
End If
End If
Else
If cboFilter.Text = "--Select--" Then
lblErrFilter.Visible = True
End If
lblError.Visible = True
lblError.Text = "No value specified for the following parameter(s) *."
End If
'Response.Redirect("~/Sites/CD/TopCon.aspx", True)
End Sub
as you can see the execution is done after I click on the filter button.
Here is my page load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If User.Identity.IsAuthenticated = False Then
Response.Redirect("/Default.aspx", True)
Else
If User.IsInRole("chicken") = True Or User.IsInRole("dog") = True Or User.IsInRole("cat") = True Then
If Not IsPostBack Then
maxTop = 10
txtTop.Text = maxTop
Call bindData()
Call bindGrid()
lblUser.Text = lblUser.Text & User.Identity.Name
lblIP.Text = lblIP.Text & GetIPAddress()
cboFilter.TabIndex = 0
Call fillYear()
Call fillDMZCombo()
Call fillZoneCombo()
Call fillType()
Else
*Call bindGrid()*
End If
Else
Response.Redirect("/Default.aspx", True)
End If
End If
End Sub
Well I know the reason why the gridview refreshes when I click on my control that is set to autopostback it's because of the bindGrid that I inserted on my page_load inside the else.
It really seems to be a passive line of code. What really bothers me is why is it that my bindGrid inside the filter button does not execute when I query 100 records or more.
Here is my code for bindGrid:
Public Sub bindGrid()
IpAdd = GetIPAddress()
xUser = User.Identity.Name
ShowCon = New SqlConnection("some data connection")
ShowCon.Open()
cmdShowCon = ShowCon.CreateCommand
cmdShowCon.CommandTimeout = 600
cmdShowCon.CommandText = "some simple select statement"
daShowCon.SelectCommand = cmdShowCon
dsShowCon.Clear()
daShowCon.Fill(dsShowCon, "someTable")
grdTopCon.DataSource = dsShowCon
grdTopCon.DataBind()
End Sub
Any help would be much appreciated.

Try setting a breakpoint in the btnFilter_Click to see what's causing the problem. It maybe either caused by the algorithm inside it or inside the Page_Load event.

Related

hide datepicker using its type

I am using the below code to Hide TextBox , Label and Dropdownlist. But how would i hide a datepicker ? can i do the same for datepicker in the below code ?
If (TypeOf ctrTexbox Is TextBox) Then
If isMasked Then
CType(ctrLabel, Label).Visible = True
CType(ctrTexbox, TextBox).Visible = False
Else
CType(ctrLabel, Label).Visible = False
CType(ctrTexbox, TextBox).Visible = True
End If
ElseIf (TypeOf ctrTexbox Is DropDownList) Then
If isMasked Then
CType(ctrLabel, Label).Visible = True
CType(ctrTexbox, DropDownList).Visible = False
Else
CType(ctrLabel, Label).Visible = False
CType(ctrTexbox, DropDownList).Visible = True
End If
html for datepicker
<BDP:BasicDatePicker Style="z-index: 205; left: 312px" ID="dtp" runat="server" width="250px" SelectedDate="1989-01-01" DateFormat="dd/MMM/yyyy">
<TextBoxStyle CssClass="inputbox" Width="250px" /></BDP:BasicDatePicker>
Sure you can, as BasicDatePicker is also derived from the same WebControl class :
ElseIf (TypeOf ctrTexbox Is BasicFrame.WebControls.BasicDatePicker) Then
If isMasked Then
CType(ctrLabel, Label).Visible = True
CType(ctrTexbox, BasicFrame.WebControls.BasicDatePicker).Visible = False
Else
CType(ctrLabel, Label).Visible = False
CType(ctrTexbox, BasicFrame.WebControls.BasicDatePicker).Visible = True
End If

Update statement in asp.net encountered with logic error?

I'm developing a project where user can can edit/update their profile, but somehow I found myself in trouble when try to update the data into Access Database. The only funniest thing is, ONLY profile picture is updated/change in database, but none for password, firstname, lastname, etc. The rest still the same. I hope someone can help me in this case, thanks in advance!
The Page Load:
If Not IsPostBack Then
DropDownList1.DataBind()
End If
LinkButtonCancel.Visible = False
FileuploadProfPic.Visible = False
TextBoxCfrmPassword.Visible = False
ButtonUpdateProf.Visible = False
TextBoxImage.Visible = False
LabelUpload.Visible = False
LabelCfnPss.Visible = False
TextBoxUsername.Enabled = False
TextBoxPassword.Enabled = False
TextBoxFirstName.Enabled = False
TextBoxLastName.Enabled = False
TextBoxEmail.Enabled = False
TextBoxHPN.Enabled = False
TextBoxUsername.ReadOnly = True
TextBoxPassword.ReadOnly = True
TextBoxFirstName.ReadOnly = True
TextBoxLastName.ReadOnly = True
TextBoxEmail.ReadOnly = True
TextBoxHPN.ReadOnly = True
UserData = Me.Data()
TextBoxUsername.Text = UserData.Username
TextBoxFirstName.Text = UserData.FirstName
TextBoxLastName.Text = UserData.LastName
TextBoxHPN.Text = UserData.MobileNumber
TextBoxEmail.Text = UserData.Email
ProfilePic.ImageUrl = UserData.ProfilePic
TextBoxImage.Text = UserData.ProfilePic
TextBoxPassword.Text = UserData.Password
The Data Function to call the data from database:
Dim dvLogin As DataView = CType(AccessDataSourceProfile.Select(DataSourceSelectArguments.Empty), DataView)
dvLogin.RowFilter = "Username = '" & DropDownList1.SelectedValue & "'"
Dim Dt As New UserLogin
Dt.Username = dvLogin(0)("Username").ToString
Dt.Password = dvLogin(0)("Password").ToString
Dt.FirstName = dvLogin(0)("FirstName").ToString
Dt.LastName = dvLogin(0)("LastName").ToString
Dt.MobileNumber = dvLogin(0)("MobileNumber").ToString
Dt.Email = dvLogin(0)("Email").ToString
Dt.ProfilePic = dvLogin(0)("ProfilePic").ToString
Return Dt
The Update Button:
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Product.mdb") & ";Jet OLEDB:Database Password=;"
objConn.ConnectionString = strConnString
objConn.Open()
Dim savePath As String = "C:\Users\AdananLong\Documents\Visual Studio 2010\Projects\E-Commerce\E-Commerce\"
If (FileuploadProfPic.HasFile) Then
Dim files As String = FileuploadProfPic.FileName
savePath += files
FileuploadProfPic.SaveAs(savePath)
TextBoxImage.Text = files
Try
objCmd = New OleDbCommand("UPDATE Member SET [Password] = #password, FirstName = #firstname, LastName = #lastname, MobileNumber = #mobilenumber, Email = #email, ProfilePic = #profilepic WHERE Username = #username", objConn)
objCmd.Parameters.AddWithValue("#password", TextBoxPassword.Text)
objCmd.Parameters.AddWithValue("#firstname", TextBoxFirstName.Text)
objCmd.Parameters.AddWithValue("#lastname", TextBoxLastName.Text)
objCmd.Parameters.AddWithValue("#mobilenumber", TextBoxHPN.Text)
objCmd.Parameters.AddWithValue("#email", TextBoxEmail.Text)
objCmd.Parameters.AddWithValue("#profilepic", TextBoxImage.Text)
objCmd.Parameters.AddWithValue("#username", TextBoxUsername.Text)
objCmd.ExecuteNonQuery()
DropDownList1.DataBind()
Me.LabelWarning.Visible = True
Me.LabelWarning.Text = "Update Sucessful."
Catch ex As Exception
Me.LabelWarning.Visible = True
Me.LabelWarning.Text = "Cannot Update : Error (" & ex.Message & ")"
End Try
Else
Try
objCmd = New OleDbCommand("UPDATE Member SET [Password] = #password, FirstName = #firstname, LastName = #lastname, MobileNumber = #mobilenumber, Email = #email, ProfilePic = #profilepic WHERE Username = #username", objConn)
objCmd.Parameters.AddWithValue("#password", TextBoxPassword.Text)
objCmd.Parameters.AddWithValue("#firstname", TextBoxFirstName.Text)
objCmd.Parameters.AddWithValue("#lastname", TextBoxLastName.Text)
objCmd.Parameters.AddWithValue("#mobilenumber", TextBoxHPN.Text)
objCmd.Parameters.AddWithValue("#email", TextBoxEmail.Text)
objCmd.Parameters.AddWithValue("#profilepic", TextBoxImage.Text)
objCmd.Parameters.AddWithValue("#username", TextBoxUsername.Text)
objCmd.ExecuteNonQuery()
DropDownList1.DataBind()
Me.LabelWarning.Visible = True
Me.LabelWarning.Text = "Update Sucessful."
Catch ex As Exception
Me.LabelWarning.Visible = True
Me.LabelWarning.Text = "Cannot Update : Error (" & ex.Message & ")"
End Try
End If
objConn.Close()
objConn = Nothing
This seems to be a well know effect of forgetting to test for postbacks in the Page_Load code.
Every time your user triggers an event to be handled on the server (runat="server" and/or AutoPostBack="true" ) then the Page.Load event of your page is called BEFORE calling the event handler activated by the user action. See ASP.NET Life Cycle
This means that in your Page.Load code you should be careful to not reload the page controls with values from the database otherwise, when the event handler is started, you have the controls filled with the original values extracted in the Page.Load event.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
.....
' code to load the controls with values from database
UserData = Me.Data()
TextBoxUsername.Text = UserData.Username
TextBoxFirstName.Text = UserData.FirstName
TextBoxLastName.Text = UserData.LastName
TextBoxHPN.Text = UserData.MobileNumber
TextBoxEmail.Text = UserData.Email
ProfilePic.ImageUrl = UserData.ProfilePic
TextBoxImage.Text = UserData.ProfilePic
TextBoxPassword.Text = UserData.Password
End If
End Sub

Trying to make a group of fields required on combobox selection in Access 2010

In Access 2010.
I have 3 separate groups of fields that can be active based on a combobox selection but I'm trying to get them to be required as well. I've looked everywhere but it doesn't appear to be any VB code to make a field required. Is there anyway I can accomplish this?
The code I have right now to make the selected group of fields active and make the one's not selected blank:
Private Sub Combo109_Click()
If Combo109 = "Germ" Then
cg_moisture.Enabled = True
cg_oil_nir.Enabled = True
extraneous_material.Enabled = True
fines.Enabled = True
cg_moisture.Enabled = True
cg_oil_nir.Enabled = True
extraneous_material.Enabled = True
fines.Enabled = True
Moist_cgm_nir.Enabled = False
prot_cgm_nir.Enabled = False
oil_cgm_nir.Enabled = False
meal_color.Enabled = False
load_out_temp.Enabled = False
moist_cgf_nir.Enabled = False
prot_cgf_nir.Enabled = False
oil_cgf_nir.Enabled = False
profat_nir.Enabled = False
starch_nir.Enabled = False
total_sug_nir.Enabled = False
loadout_temp.Enabled = False
screen_thrus.Enabled = False
screen_thrus.Value = ""
Moist_cgm_nir.Value = ""
prot_cgm_nir.Value = ""
oil_cgm_nir.Value = ""
meal_color.Value = ""
load_out_temp.Value = ""
moist_cgf_nir.Value = ""
prot_cgf_nir.Value = ""
oil_cgf_nir.Value = ""
profat_nir.Value = ""
starch_nir.Value = ""
total_sug_nir.Value = ""
loadout_temp.Value = ""
screen_thrus.Value = ""
screen_thrus.Value = ""
End If
IF all of the controls are in the 'Detail' section of your form, AND if a contrtol is Enabled, you require a value, then the code below should work. If you want more meaningful names to be displayed, either change your control names, or place a better name in the control 'Tag' field and reference that. The following code only checks Textboxes and CheckBoxes - modify to suit your needs.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
Dim blnMissing As Boolean
Dim strMissing As String
For Each ctl In Me.Section("Detail").Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acCheckBox Then
If ctl.Enabled = True Then
'Debug.Print ctl.Name & vbTab & ctl.Value
If ctl.Properties("Enabled") = True Then
If Me(ctl.Name) = "" Or IsNull(Me(ctl.Name)) Then
blnMissing = True
strMissing = strMissing & ctl.Name & "; "
End If
End If
End If
End If
Next ctl
If blnMissing = True Then
MsgBox "You are required to enter data in fields: " & strMissing, vbOKOnly + vbCritical, "Missing Required Data"
Cancel = True
End If
End Sub

Conversion from string “” to type 'Byte' is not valid [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have been struggling with this error for a couple days now, I have gone over the code to try to find an instance where I have the wrong type, but no luck. I am getting the "Conversion from string “” to type 'Byte' is not valid" when the submit button is clicked. So my thought is that there is something wrong in the Data_Save function. But I am unable to see my mistake. any help would be appreciated.
Protected Function Data_Save() As Boolean
Data_Save = False
Try
Dim newTable As New DemoOp_WebDataTable
Dim newRow As DemoOp_WebRow = newTable.NewRow()
newRow.DOW_FName = Me.txtFName.Text
newRow.DOW_LName = Me.txtLName.Text
newRow.DOW_Addr_1 = Me.txtAddr_1.Text
newRow.DOW_Addr_2 = Me.txtAddr_2.Text
newRow.DOW_City = Me.txtCity.Text
newRow.DOW_State = Me.ddState.SelectedValue.ToString
newRow.DOW_Zip = Me.txtZip.Text
newRow.DOW_Home_Phone = Me.txtHome_Phone.Text
newRow.DOW_Work_Phone = String.Empty
newRow.DOW_Cell_Phone = Me.txtCell_Phone.Text
newRow.DOW_Email = Me.txtEmail.Text
newRow.DOW_Dem_Exp = String.Empty
newRow.DOW_Wkd_Ret = String.Empty
newRow.DOW_Bilingual = String.Empty
newRow.DOW_Lang_Spk = String.Empty
newRow.DOW_Hrd_Store = Me.ddlOptQst12.SelectedItem.Value
newRow.DOW_StoreCode = Me.ddAd_Code.SelectedValue.ToString
newRow.DOW_In_Date = Now
newRow.DOW_18Plus = Me.rblnewqst1.SelectedValue
newRow.DOW_Transportation = Me.rblnewqst2.SelectedValue
newRow.DOW_AbleToStand = Me.rblnewqst3.SelectedValue
newRow.DOW_Internet = Me.rblnewqst4.SelectedValue
newRow.DOW_DirectDeposit = Me.rblnewqst5.SelectedValue
newRow.DOW_Experience = Me.rblnewqst6.SelectedValue
newRow.DOW_Outgoing = Me.rblnewqst7.SelectedValue
newRow.DOW_CulinarySkills = Me.rblnewqst8.SelectedValue
newRow.DOW_DemoWorkType = Me.ddlOptQst1.SelectedItem.Value
newRow.DOW_ReceiveTextMsgs = Me.rblOptQst2.SelectedValue
newRow.DOW_AgeCategory = Me.ddlOptQst3.SelectedItem.Value
newRow.DOW_ComputerSkill = Me.ddlOptQst4.SelectedItem.Value
newRow.DOW_CookingSkill = Me.ddlOptQst5.SelectedItem.Value
newRow.DOW_PhysicallyFit = Me.ddlOptQst6.SelectedItem.Value
newRow.DOW_AreasOfExp = GetCheckValues(chkOptQst7)
newRow.DOW_SpecialExpertise = GetCheckValues(chkOptQst8)
newRow.DOW_OtherLanguage = Me.ddlOptQst9.SelectedItem.Value
newRow.DOW_Felony = Me.rblnewqst11.SelectedValue
newRow.DOW_SOffender = Me.rblnewqst12.SelectedValue
newRow.DOW_ShopLift = Me.rblnewqst13.SelectedValue
newRow.DOW_FoodHandlers = Me.rblnewqst10.SelectedValue
newRow.DOW_OtherAgencies = GetCheckValues(chkOptQst10)
newRow.DOW_CookingAppliances = GetCheckValues(chkOptQst11)
newRow.DOW_Hrd_Store_Detail = Me.ddlOptQst13.SelectedItem.Value
Dim ta As DemoOp_WebTableAdapter = New DemoOp_WebTableAdapter
'ta.Insert(newRow.DOW_FName, newRow.DOW_LName, newRow.DOW_Addr_1, newRow.DOW_Addr_2, newRow.DOW_City, _
' newRow.DOW_State, newRow.DOW_Zip, newRow.DOW_Home_Phone, newRow.DOW_Work_Phone, newRow.DOW_Cell_Phone, _
' newRow.DOW_Email, newRow.DOW_Dem_Exp, newRow.DOW_Wkd_Ret, newRow.DOW_Bilingual, newRow.DOW_Lang_Spk, _
' newRow.DOW_Hrd_Store, newRow.DOW_Hrd_Store_Detail, newRow.DOW_StoreCode, newRow.DOW_18Plus, newRow.DOW_Transportation, _
' newRow.DOW_AbleToStand, newRow.DOW_Internet, newRow.DOW_DirectDeposit, newRow.DOW_Felony, newRow.DOW_SOffender, newRow.DOW_ShopLift, newRow.DOW_Experience, _
' newRow.DOW_Outgoing, newRow.DOW_CulinarySkills, newRow.DOW_FoodHandlers, newRow.DOW_DemoWorkType, newRow.DOW_ReceiveTextMsgs, _
' newRow.DOW_AgeCategory, newRow.DOW_ComputerSkill, newRow.DOW_CookingSkill, newRow.DOW_PhysicallyFit, _
' newRow.DOW_AreasOfExp, newRow.DOW_SpecialExpertise, newRow.DOW_OtherAgencies, newRow.DOW_CookingAppliances, newRow.DOW_OtherLanguage)
ta.Insert(newRow.DOW_FName, newRow.DOW_LName, newRow.DOW_Addr_1, newRow.DOW_Addr_2, newRow.DOW_City, _
newRow.DOW_State, newRow.DOW_Zip, newRow.DOW_Home_Phone, newRow.DOW_Work_Phone, newRow.DOW_Cell_Phone, _
newRow.DOW_Email, newRow.DOW_Dem_Exp, newRow.DOW_Wkd_Ret, newRow.DOW_Bilingual, newRow.DOW_Lang_Spk, _
newRow.DOW_Hrd_Store, newRow.DOW_StoreCode, newRow.DOW_18Plus, newRow.DOW_Transportation, _
newRow.DOW_AbleToStand, newRow.DOW_Internet, newRow.DOW_DirectDeposit, newRow.DOW_Experience, _
newRow.DOW_Outgoing, newRow.DOW_CulinarySkills, newRow.DOW_DemoWorkType, newRow.DOW_ReceiveTextMsgs, _
newRow.DOW_AgeCategory, newRow.DOW_ComputerSkill, newRow.DOW_CookingSkill, newRow.DOW_PhysicallyFit, _
newRow.DOW_AreasOfExp, newRow.DOW_SpecialExpertise, newRow.DOW_OtherLanguage, newRow.DOW_Felony, newRow.DOW_SOffender, newRow.DOW_ShopLift, newRow.DOW_FoodHandlers, newRow.DOW_OtherAgencies, newRow.DOW_CookingAppliances, newRow.DOW_Hrd_Store_Detail)
Data_Save = True
Catch ex As ApplicationException
Me.lblErrMessage.Text = ex.InnerException.ToString
End Try
End Function
Protected Function GetCheckValues(ByVal chklst As CheckBoxList) As String
GetCheckValues = String.Empty
Dim i As Integer
Dim sb As StringBuilder = New StringBuilder()
For i = 0 To chklst.Items.Count - 1
If chklst.Items(i).Selected Then
sb.Append(chklst.Items(i).Value & ",")
End If
Next
'remove the last comma in sb
If sb.Length > 0 Then
Dim InputValue As String
InputValue = Left(sb.ToString(), Len(sb.ToString()) - 1)
GetCheckValues = InputValue
End If
End Function
Protected Sub Reset_Controls()
btnSubmit.Visible = False
btnCancel.Visible = False
btnBack.Visible = True
txtFName.Enabled = False
txtLName.Enabled = False
txtAddr_1.Enabled = False
txtAddr_2.Enabled = False
txtCity.Enabled = False
ddState.Enabled = False
txtZip.Enabled = False
txtHome_Phone.Enabled = False
txtCell_Phone.Enabled = False
txtEmail.Enabled = False
ddlOptQst12.Enabled = False
ddlOptQst13.Enabled = False
ddStoreCode.Enabled = False
rblnewqst1.Enabled = False
rblnewqst2.Enabled = False
rblnewqst3.Enabled = False
rblnewqst4.Enabled = False
rblnewqst5.Enabled = False
rblnewqst6.Enabled = False
rblnewqst7.Enabled = False
rblnewqst8.Enabled = False
rblnewqst10.Enabled = False
rblnewqst11.Enabled = False
rblnewqst12.Enabled = False
rblnewqst13.Enabled = False
ddlOptQst1.Enabled = False
rblOptQst2.Enabled = False
ddlOptQst3.Enabled = False
ddlOptQst4.Enabled = False
ddlOptQst5.Enabled = False
ddlOptQst6.Enabled = False
chkOptQst7.Enabled = False
chkOptQst8.Enabled = False
ddlOptQst9.Enabled = False
chkOptQst10.Enabled = False
chkOptQst11.Enabled = False
End Sub
Protected Sub btnOKMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Data_Save() Then
lblErrMessage.Text = "Your information has been submitted!"
Else
lblErrMessage.Text = "Error occurred while saving your entry. Click on 'Back' to return to main page."
End If
'Reset_Controls()
ModalPopupExtender1.Hide()
End Sub
Protected Sub btnCancelMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
lblErrMessage.Text = "Your information was previously submitted."
ModalPopupExtender1.Hide()
End Sub
End Class
Here's a couple of suggestions to get you started:
Enable "Option strict" in your project options and fix any errors you may get. This will help you identify where you're trying to set a byte value with an empty string.
Remove all the try-catch-statements with an empty catch section.
Clean up the code, and remove the sections not relevant to your question.
Tell us where the exception occurs and the exception details...

Session disappears unexpectedly

The site is a buy/sell site and the page the code comes from is the "add product" page.
The problem is that the session("change") becomes nothing by some reason, I can't find any errors. The payment.aspx have a button that sends me back to the page with a session("change").
The reason I see the problem is that when I try to edit something the category gets restetted to the first in the list. and when I debug I see that the session is nothing, though it should be something
Heres the code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
If Not stats > 0 Then
If Session("change") IsNot Nothing Then
Dim dc As New DataClassesDataContext
Dim getP = From prod In dc.Products _
Where prod.ProductID = CInt(Session("change")) _
Select prod
If getP.Any Then
If rdbSell.Checked = True Then
getP.FirstOrDefault.BuySell = True
Else
getP.FirstOrDefault.BuySell = False
End If
If ddlSubSubcat.SelectedValue IsNot String.Empty Then
getP.FirstOrDefault.CategoryID = CInt(ddlSubSubcat.SelectedValue)
Else
getP.FirstOrDefault.CategoryID = CInt(ddlSubCat.SelectedValue)
End If
getP.FirstOrDefault.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
getP.FirstOrDefault.CountyID = CInt(ddlCounty.SelectedValue)
getP.FirstOrDefault.E_mail = txtEmail.Text
getP.FirstOrDefault.Date = DateTime.Now
getP.FirstOrDefault.Active = 0
getP.FirstOrDefault.Alias = txtAlias.Text.Replace("'", "''")
getP.FirstOrDefault.ShowEmail = 0
Dim PreID As Integer = getP.FirstOrDefault.ProductID
If chkShowEmail.Checked = True Then
getP.FirstOrDefault.ShowEmail = 1
Else
getP.FirstOrDefault.ShowEmail = 0
End If
If chkShowPhone.Checked = True Then
getP.FirstOrDefault.ShowPhone = 1
Else
getP.FirstOrDefault.ShowPhone = 0
End If
getP.FirstOrDefault.Headline = txtHeadline.Text
getP.FirstOrDefault.Password = txtPassword.Text
getP.FirstOrDefault.Phone = txtPhone.Text
getP.FirstOrDefault.Price = txtPrice.Text
If chkUnknown.Checked = True Then
getP.FirstOrDefault.YearModel = String.Empty
Else
getP.FirstOrDefault.YearModel = ddlYear.SelectedValue
End If
For Each item In libPictures.Items
Dim i As String = item.ToString
Dim imagecheck = From img In dc.Pictures _
Where img.Name = i And img.ProductID = CInt(Session("change")) _
Select img
If imagecheck.Any Then
Else
Dim img As New Picture
img.Name = item.ToString
img.ProductID = CInt(Session("change"))
dc.Pictures.InsertOnSubmit(img)
dc.SubmitChanges()
End If
Next
dc.SubmitChanges()
Session.Remove("change")
Response.Redirect("~/precheck.aspx?id=" + PreID.ToString)
End If
Else
Dim dc As New DataClassesDataContext
Dim prod As New Product
If rdbSell.Checked = True Then
prod.BuySell = True
Else
prod.BuySell = False
End If
If ddlSubSubcat.DataValueField IsNot String.Empty Then
prod.CategoryID = CInt(ddlSubSubcat.SelectedValue)
Else
prod.CategoryID = CInt(ddlSubCat.SelectedValue)
End If
prod.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
prod.CountyID = CInt(ddlCounty.SelectedValue)
prod.E_mail = txtEmail.Text
prod.Date = DateTime.Now
prod.Active = 0
prod.Alias = txtAlias.Text.Replace("'", "''")
prod.ShowEmail = 0
If chkShowEmail.Checked = True Then
prod.ShowEmail = 1
Else
prod.ShowEmail = 0
End If
If chkShowPhone.Checked = True Then
prod.ShowPhone = 1
Else
prod.ShowPhone = 0
End If
prod.Headline = txtHeadline.Text
prod.Password = txtPassword.Text
prod.Phone = txtPhone.Text
prod.Price = txtPrice.Text
If chkUnknown.Checked = True Then
prod.YearModel = String.Empty
Else
prod.YearModel = ddlYear.SelectedValue
End If
dc.Products.InsertOnSubmit(prod)
dc.SubmitChanges()
Dim PreID As Integer = prod.ProductID
For Each item In libPictures.Items
Dim img As New Picture
img.Name = item.ToString
img.ProductID = prod.ProductID
dc.Pictures.InsertOnSubmit(img)
dc.SubmitChanges()
Next
Session.Remove("change")
Response.Redirect("./precheck.aspx?id=" + PreID.ToString, False)
End If
End If
stats = 0
'Catch ex As Exception
'End Try
End Sub
It depends upon how the application is managing session state. If your session state is managed InProc then if the application pool is recycled then all your session information will be lost. If that is happening then it could be a good option to store session state in SQL Server which will persist between app pool recycling.
More info:
ASP.NET Session State Overview
ASP.NET State Management Recommendations

Resources