other gridview is used for entry of education qualifications.
My application works successfully for displaying records of education qualification of employees.
When I click on an one employee in 1st gridview, it displays qualifications in 2nd gridview.
The problem occurs when I save qualification of 1 employee and display successful message in another form and then return to same form for entry of 2nd employee, it gives above mentioned error.
I have to run program every time for entry of qualifications of each employee. Presently my program is in developmental stage and I am checking my program for every data entry.
Note: This error comes after saving qualifications of any 1 employee and after clicking any command button.
After then on every clicking I am getting following error message.
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments
to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports WebService
Partial Class PersonQualificationDetail
Inherits System.Web.UI.Page
Dim strSQL As String
Dim connString As String = ConfigurationSettings.AppSettings("connection1")
Dim conn As New OleDbConnection(connString)
Dim oleDbCommand As New OleDbCommand
Dim webService As New WebService
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("appName") = "PersonQualificationDetail.aspx"
If Session("userID") = "" Then
Response.Redirect("Default.aspx")
Else
If Not IsPostBack Then
strSQL = "SELECT COUNT(*) FROM options WHERE firsttime = 'N'"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT.Rows(0).Item(0) = 1 Then
Dim mpLogLabel As Label
Dim mpLogButton As Button
mpLogLabel = CType(Master.FindControl("LogLabel"), Label)
If Not mpLogLabel Is Nothing Then
mpLogLabel.Text = "Welcome " + Session("UserID").ToString
End If
mpLogButton = CType(Master.FindControl("LogButton"), Button)
If Not mpLogButton Is Nothing Then
mpLogButton.Text = "Log Out"
End If
End If
ClearValues()
RefreshList()
bindData()
bindData1()
findAndColorRowInGridView()
disabledText()
ChangeCommandStatus(1)
If Session("pageWise").ToString <> "" Then
PagewiseCheckBox.Checked = Session("pageWise")
GridView1.AllowPaging = True
GridView1.PageIndex = Convert.ToInt32(Session("pagingInfo"))
End If
Session("keyValue") = "0"
MessageLabel.CssClass = "SuccessMessage"
MessageLabel.Text = "New Entry"
End If
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.Text = "" Then
clearValues()
Session("keyValue") = ""
ChangeCommandStatus(1)
Else
Session("keyValue") = DropDownList1.Text
displayData(Session("keyValue"))
ChangeCommandStatus(2)
End If
findAndColorRowInGridView()
End Sub
Protected Sub PageList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PageList.SelectedIndexChanged
GridView1.PageIndex = Convert.ToInt32(PageList.SelectedValue)
'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
bindData()
findAndColorRowInGridView()
End Sub
Protected Sub PagewiseCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PagewiseCheckBox.CheckedChanged
If PagewiseCheckBox.Checked = True Then
GridView1.AllowPaging = True
Else
GridView1.AllowPaging = False
End If
'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
bindData()
findAndColorRowInGridView()
End Sub
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
'Clear our all of the items in the Dropdownlist
PageList.Items.Clear()
'Add a ListItem for each page
For i As Integer = 0 To GridView1.PageCount - 1
Dim pageListItem As New ListItem(String.Concat("Page ", i + 1), i.ToString())
PageList.Items.Add(pageListItem)
'select the current item, if needed
If i = GridView1.PageIndex Then
pageListItem.Selected = True
End If
Next
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = Int32.Parse(e.NewPageIndex)
bindData()
'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
findAndColorRowInGridView()
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "" Then
Dim currentRowIndex As Integer = Int32.Parse(e.CommandArgument.ToString())
Dim keyValue As String = GridView1.DataKeys(currentRowIndex).Value
Session("keyValue") = keyValue
DropDownList1.Text = keyValue
MessageLabel.Text = ""
displayData(keyValue)
End If
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "this.className='highlight'")
e.Row.Attributes.Add("onmouseout", "this.className='normal'")
End If
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If GridView1.DataKeys(e.Row.RowIndex).Value.ToString <> "" Then
strSQL = "SELECT em_personqualificationdetail FROM employees WHERE em_employeeid = '" + GridView1.DataKeys(e.Row.RowIndex).Value.ToString + "'"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT.Rows.Count = 1 Then
If DT.Rows(0).Item(0).ToString = "Y" Then
e.Row.Cells(0).BackColor = Drawing.Color.LightPink
e.Row.Cells(1).BackColor = Drawing.Color.LightPink
e.Row.Cells(2).BackColor = Drawing.Color.LightPink
e.Row.Cells(3).BackColor = Drawing.Color.LightPink
End If
End If
End If
End If
End Sub
Protected Sub QualificationGridView_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles QualificationGridView.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "this.className='highlight'")
e.Row.Attributes.Add("onmouseout", "this.className='normal'")
End If
End Sub
Protected Sub QualificationGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles QualificationGridView.RowDataBound
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(2).FindControl("QualificationDropDownList"), DropDownList)
'District List banaya
strSQL = "SELECT qm_qualificationid, qm_qualificationname FROM qualificationmaster ORDER BY qm_qualificationid ASC"
oleDbCommand.CommandType = CommandType.Text
oleDbCommand.CommandText = strSQL
oleDbCommand.Connection = conn
qualificationDropDownList.Items.Clear()
qualificationDropDownList.Items.Add(New ListItem("-Select-", ""))
qualificationDropDownList.Items.Add(New ListItem("-Other-", "0"))
Try
conn.Open()
qualificationDropDownList.DataSource = oleDbCommand.ExecuteReader()
qualificationDropDownList.DataTextField = "qm_qualificationname"
qualificationDropDownList.DataValueField = "qm_qualificationid"
qualificationDropDownList.DataBind()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
End If
Next
End Sub
Protected Sub QualificationGridView_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles QualificationGridView.RowDeleting
' Command Argument Property में मौजूद rowindex का वैल्यू निकालें.
QualificationGridView.EditIndex = e.RowIndex
' Rows collection में उस row को निकालें जिसमे button मौजूद है.
Dim gvr As GridViewRow = QualificationGridView.Rows(e.RowIndex)
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
'Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
'Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
'Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
'Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
'Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
strSQL = "DELETE FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "' AND eq_qualificationid = '" + qualificationDropDownList.Text + "' AND eq_otherqualification = '" + otherqualificationTextBox.Text + "'"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
strSQL = "SELECT eq_employeeid FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "'"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
'
If DT.Rows.Count = 0 Then
'employees टेबल में em_personqualificationdetail फील्ड का वैल्यू 'N' करना हैं.
strSQL = "UPDATE employees SET em_personqualificationdetail = 'N' WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
End If
displayData(Session("keyValue").ToString)
End Sub
Protected Sub QualificationGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles QualificationGridView.RowEditing
' rowindex का वैल्यू निकालें.
QualificationGridView.EditIndex = e.NewEditIndex
' Rows collection में उस row को निकालें जिसमे button मौजूद है.
Dim gvr As GridViewRow = QualificationGridView.Rows(e.NewEditIndex)
' सारे textbox और dropdownlist को enable कर दें ताकि अपडेट कर सकें.
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
If selectCheckBox.Checked Then
qualificationDropDownList.Enabled = True
otherqualificationTextBox.Enabled = False
streamsubjectTextBox.Enabled = True
universityboardTextBox.Enabled = True
schoolcollegeTextBox.Enabled = True
passingyearTextBox.Enabled = True
percentageTextBox.Enabled = True
End If
End Sub
Public Sub SelectCheckBox_CheckedChanged()
'Is button ka istemaal cancel command ko enable/disable karne ke vaste
Dim buttonValue As Integer = 0
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
If selectCheckBox.Checked Then
qualificationDropDownList.Enabled = True
otherqualificationTextBox.Enabled = False
streamsubjectTextBox.Enabled = True
universityboardTextBox.Enabled = True
schoolcollegeTextBox.Enabled = True
passingyearTextBox.Enabled = True
percentageTextBox.Enabled = True
buttonValue = buttonValue + 1
Else
If buttonValue = gvr.RowIndex Then
selectCheckBox.Enabled = True
Else
selectCheckBox.Enabled = False
End If
qualificationDropDownList.Enabled = False
qualificationDropDownList.SelectedValue = ""
otherqualificationTextBox.Enabled = False
streamsubjectTextBox.Enabled = False
universityboardTextBox.Enabled = False
schoolcollegeTextBox.Enabled = False
passingyearTextBox.Enabled = False
percentageTextBox.Enabled = False
End If
End If
Next
If buttonValue = 0 Then
CancelButton.Enabled = False
Else
CancelButton.Enabled = True
End If
End Sub
Public Sub QualificationDropDownList_SelectedIndexChanged()
'Is button ka istemaal save command ko enable/disable karne ke liye
Dim buttonValue As Integer = 0
Dim varQualification As String
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = DirectCast(gvr.FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = DirectCast(gvr.FindControl("OtherQualificationTextBox"), TextBox)
'Enable/Disable otherqualificationtextbox
If selectCheckBox.Checked Then
If qualificationDropDownList.SelectedValue = "0" Then
otherqualificationTextBox.Enabled = True
otherqualificationTextBox.Focus()
Else
'यहाँ पर चेक करना है कि GRIDVIEW में क्वालिफिकेशन रिपीट तो नहीं हो रहा है.
varQualification = qualificationDropDownList.Text
'अगर क्वालिफिकेशन मेट्रिक से कम है तो gridview के उस row में सारे textbox को disable करना है.
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
If CInt(Mid(qualificationDropDownList.Text, 10, 1)) <= 2 Then
streamsubjectTextBox.Enabled = False
universityboardTextBox.Enabled = False
schoolcollegeTextBox.Enabled = False
passingyearTextBox.Enabled = False
percentageTextBox.Enabled = False
Else
streamsubjectTextBox.Enabled = True
universityboardTextBox.Enabled = True
schoolcollegeTextBox.Enabled = True
passingyearTextBox.Enabled = True
percentageTextBox.Enabled = True
End If
otherqualificationTextBox.Text = ""
otherqualificationTextBox.Enabled = False
End If
Else
If qualificationDropDownList.Text = "" Then
otherqualificationTextBox.Text = ""
otherqualificationTextBox.Enabled = False
End If
End If
'Enable/Disable save command button
If qualificationDropDownList.SelectedValue <> "" Then
buttonValue = buttonValue + 1
End If
End If
Next
If buttonValue = 0 Then
SaveButton.Enabled = False
Else
SaveButton.Enabled = True
End If
End Sub
Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveButton.Click
Dim entryDate, empName, empNo As String
entryDate = "'" + Now().ToShortDateString + "'"
MessageLabel.Text = ""
Session("message1") = ""
Session("pageWise") = PagewiseCheckBox.Checked
Session("pagingInfo") = PageList.Text
'कर्मचारी का नाम को स्टोर करना है.
strSQL = "SELECT em_empname FROM employees WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
Dim DT1 As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT1)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT1.Rows.Count = 1 Then
empName = DT1.Rows(0).Item(0).ToString
Else
empName = ""
End If
'employees टेबल में em_personqualificationdetail फील्ड का वैल्यू 'Y' करना हैं.
strSQL = "UPDATE employees SET em_personqualificationdetail = 'Y' WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
'saving education details
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
'Enable/Disable othertextbox
If selectCheckBox.Checked Then
strSQL = "INSERT into employeequalification (eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision, eq_createdby, eq_createdate) VALUES ('" + Session("keyValue").ToString + "', '" + qualificationDropDownList.Text + "', '" + otherqualificationTextBox.Text.ToUpper + "', '" + streamsubjectTextBox.Text.ToUpper + "', '" + universityboardTextBox.Text.ToUpper + "', '" + schoolcollegeTextBox.Text.ToUpper + "', '" + passingyearTextBox.Text + "', '" + percentageTextBox.Text + "', '" + Session("userID").ToString + "', " + entryDate + ")"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
End If
End If
Next
empNo = Session("keyValue").ToString
Session("keyValue") = "0" 'Is session variable ko yahin par saaf karna matlab 0(zero) taki update ke check na kare.
RefreshList()
ChangeCommandStatus(1)
ClearValues()
disabledText()
bindData()
If Len(MessageLabel.Text) = 0 Then
MessageLabel.CssClass = "SuccessMessage"
MessageLabel.Text = "व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सफलतापूर्वक सेव कर लिया गया है."
Session("message1") = MessageLabel.Text
MesgBox()
Else
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = "माफ़ कीजिये! व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सेव नहीं हो पाया है."
Session("message1") = MessageLabel.Text
MesgBox()
End If
End Sub
Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim entryDate, empNo, empName As String
entryDate = "'" + Now().ToShortDateString + "'"
MessageLabel.Text = ""
Session("message1") = ""
Session("pageWise") = PagewiseCheckBox.Checked
Session("pagingInfo") = PageList.Text
'Employee name ko store karna hai.
strSQL = "SELECT em_empname, em_personqualificationdetail FROM employees WHERE em_employeeid = '" + Session("keyValue").ToString + "'"
Dim DT1 As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT1)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT1.Rows.Count = 1 Then
empName = DT1.Rows(0).Item(0).ToString
Else
empName = ""
End If
'employee ka education equalification check karo, agar pahle se hai to update karo nahi to insert karo
strSQL = "SELECT eq_employeeid, eq_qualificationid FROM employeequalification WHERE eq_employeeid = '" + Session("keyValue").ToString + "'"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
'Updating education details record.
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
'Enable/Disable othertextbox
If selectCheckBox.Checked Then
If DT.Rows.Count > 0 Then
Dim counter As Integer = 0
Do While counter < DT.Rows.Count
If DT.Rows(counter).Item(1).ToString = qualificationDropDownList.Text Then
strSQL = "UPDATE employeequalification SET eq_qualificationid = '" + qualificationDropDownList.Text + "', eq_otherqualification = '" + otherqualificationTextBox.Text.ToUpper + "', eq_streamsubject = '" + streamsubjectTextBox.Text.ToUpper + "', eq_universityboard = '" + universityboardTextBox.Text.ToUpper + "', eq_schoolcollege = '" + schoolcollegeTextBox.Text.ToUpper + "', eq_passingyear = '" + passingyearTextBox.Text + "', eq_percentdivision = '" + percentageTextBox.Text + "', eq_updatedby = '" + Session("userID").ToString + "', eq_updatedate = " + entryDate + " WHERE eq_employeeid = '" + Session("keyValue").ToString + "' AND eq_qualificationid = '" + qualificationDropDownList.Text + "'"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
counter = DT.Rows.Count + 1
Else
counter = counter + 1
End If
Loop
If counter = DT.Rows.Count Then
strSQL = "INSERT into employeequalification (eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision, eq_createdby, eq_createdate) VALUES ('" + Session("keyValue").ToString + "', '" + qualificationDropDownList.Text + "', '" + otherqualificationTextBox.Text.ToUpper + "', '" + streamsubjectTextBox.Text.ToUpper + "', '" + universityboardTextBox.Text.ToUpper + "', '" + schoolcollegeTextBox.Text.ToUpper + "', '" + passingyearTextBox.Text + "', '" + percentageTextBox.Text + "', '" + Session("userID").ToString + "', " + entryDate + ")"
Try
conn.Open()
oleDbCommand = New OleDbCommand(strSQL, conn)
oleDbCommand.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
End If
End If
End If
End If
Next
empNo = Session("keyValue").ToString
Session("keyValue") = "0" 'Is session variable ko yahin par saaf karna matlab 0(zero) taki update ke check na kare.
RefreshList()
ChangeCommandStatus(1)
ClearValues()
disabledText()
bindData()
If Len(MessageLabel.Text) = 0 Then
MessageLabel.CssClass = "SuccessMessage"
MessageLabel.Text = "व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स सफलतापूर्वक अपडेट कर लिया गया है."
Session("message1") = MessageLabel.Text
MesgBox()
Else
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = "माफ़ कीजिये! व्यक्ति " + empNo + " [" + empName + "] का एजुकेशनल डिटेल्स अपडेट नहीं हो पाया है."
Session("message1") = MessageLabel.Text
MesgBox()
End If
End Sub
Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CancelButton.Click
RefreshList()
ChangeCommandStatus(1)
ClearValues()
disabledText()
Session("keyValue") = "0"
DropDownList1.Text = ""
bindData()
MessageLabel.CssClass = "SuccessMessage"
MessageLabel.Text = "New Entry"
End Sub
Protected Sub BackButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BackButton.Click
ChangeCommandStatus(0)
clearValues()
Session("keyValue") = "0"
Response.Redirect("Default.aspx")
End Sub
Sub displayData(ByVal keyValue As String)
ClearValues()
'extract name and flag for new or old data
strSQL = "SELECT em_employeeid, em_empname, em_personqualificationdetail FROM employees WHERE em_employeeid = '" + keyValue + "'"
Dim DT1 As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT1)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT1.Rows.Count = 1 Then
NameTextLabel.Text = DT1.Rows(0).Item(1).ToString
If DT1.Rows(0).Item(2).ToString = "" Then
ChangeCommandStatus(1) 'Enable/disable command buttons
Else
ChangeCommandStatus(2) 'Enable/disable command buttons
End If
End If
strSQL = "SELECT eq_employeeid, eq_qualificationid, eq_otherqualification, eq_streamsubject, eq_universityboard, eq_schoolcollege, eq_passingyear, eq_percentdivision FROM employeequalification WHERE eq_employeeid = '" + keyValue + "'"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
'Edit interface me data bharaa
If DT.Rows.Count > 0 Then
Dim counter As Integer = 0
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
If counter < DT.Rows.Count Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
qualificationDropDownList.Text = DT.Rows(counter).Item(1).ToString
otherqualificationTextBox.Text = DT.Rows(counter).Item(2).ToString
streamsubjectTextBox.Text = DT.Rows(counter).Item(3).ToString
universityboardTextBox.Text = DT.Rows(counter).Item(4).ToString
schoolcollegeTextBox.Text = DT.Rows(counter).Item(5).ToString
passingyearTextBox.Text = DT.Rows(counter).Item(6).ToString
percentageTextBox.Text = DT.Rows(counter).Item(7).ToString
selectCheckBox.Checked = True
selectCheckBox.Enabled = False
editButton.Enabled = True
deleteButton.Enabled = True
counter = counter + 1
End If
End If
Dim select1CheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
If counter = gvr.RowIndex Then
select1CheckBox.Enabled = True
Else
select1CheckBox.Enabled = False
End If
Next
Else
For Each gvr As GridViewRow In QualificationGridView.Rows
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
If gvr.RowIndex = 0 Then
selectCheckBox.Enabled = True
Else
selectCheckBox.Enabled = False
End If
Next
End If
'selected row ka color change karo.
'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
findAndColorRowInGridView()
End Sub
Private Sub bindData()
strSQL = "SELECT em_employeeid, em_empname, em_birthdate FROM employees WHERE MID(em_employeeid,3,2) <>'00' ORDER BY em_employeeid ASC"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT.Rows.Count > 0 Then
If DT.Rows.Count > GridView1.PageSize Then
PagingLabel.Enabled = True
PageList.Enabled = True
PagewiseCheckBox.Enabled = True
Else
PagingLabel.Enabled = False
PageList.Enabled = False
PagewiseCheckBox.Enabled = False
End If
GridView1.DataSource = DT
GridView1.DataBind()
Else
GridView1.DataSource = Nothing
GridView1.DataBind()
End If
End Sub
Private Sub bindData1()
strSQL = "SELECT qm_qualificationid, qm_qualificationname FROM qualificationmaster"
Dim DT As New DataTable
Try
Dim DA As New OleDbDataAdapter(strSQL, conn)
DA.Fill(DT)
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
If DT.Rows.Count > 0 Then
QualificationGridView.DataSource = DT
QualificationGridView.DataBind()
Else
QualificationGridView.DataSource = Nothing
QualificationGridView.DataBind()
End If
End Sub
Sub RefreshList()
'List ko refresh kiya
strSQL = "SELECT em_employeeid, em_empname FROM employees WHERE MID(em_employeeid,3,2) <>'00' ORDER BY em_empname ASC"
oleDbCommand.CommandType = CommandType.Text
oleDbCommand.CommandText = strSQL
oleDbCommand.Connection = conn
DropDownList1.Items.Clear()
DropDownList1.Items.Add(New ListItem("-चुनें-", ""))
Try
conn.Open()
DropDownList1.DataSource = oleDbCommand.ExecuteReader()
DropDownList1.DataTextField = "em_empname"
DropDownList1.DataValueField = "em_employeeid"
DropDownList1.DataBind()
conn.Close()
Catch ex As Exception
MessageLabel.CssClass = "ErrorMessage"
MessageLabel.Text = webService.DisplayExceptionDetails(ex)
Session("message1") = MessageLabel.Text
MesgBox()
End Try
End Sub
Private Sub ClearValues()
NameTextLabel.Text = ""
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
If selectCheckBox.Checked Then
selectCheckBox.Checked = False
End If
editButton.Enabled = False
qualificationDropDownList.Enabled = False
qualificationDropDownList.SelectedValue = ""
otherqualificationTextBox.Enabled = False
otherqualificationTextBox.Text = ""
streamsubjectTextBox.Enabled = False
streamsubjectTextBox.Text = ""
universityboardTextBox.Enabled = False
universityboardTextBox.Text = ""
schoolcollegeTextBox.Enabled = False
schoolcollegeTextBox.Text = ""
passingyearTextBox.Enabled = False
passingyearTextBox.Text = ""
percentageTextBox.Enabled = False
percentageTextBox.Text = ""
deleteButton.Enabled = False
End If
Next
End Sub
Private Sub disabledText()
NameTextLabel.Enabled = False
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
Dim editButton As Button = CType(gvr.Cells(2).FindControl("EditButton"), Button)
Dim qualificationDropDownList As DropDownList = CType(gvr.Cells(3).FindControl("QualificationDropDownList"), DropDownList)
Dim otherqualificationTextBox As TextBox = CType(gvr.Cells(4).FindControl("OtherQualificationTextBox"), TextBox)
Dim streamsubjectTextBox As TextBox = CType(gvr.Cells(5).FindControl("StreamSubjectTextBox"), TextBox)
Dim universityboardTextBox As TextBox = CType(gvr.Cells(6).FindControl("UniversityBoardTextBox"), TextBox)
Dim schoolcollegeTextBox As TextBox = CType(gvr.Cells(7).FindControl("SchoolCollegeTextBox"), TextBox)
Dim passingyearTextBox As TextBox = CType(gvr.Cells(8).FindControl("PassingYearTextBox"), TextBox)
Dim percentageTextBox As TextBox = CType(gvr.Cells(9).FindControl("PercentageTextBox"), TextBox)
Dim deleteButton As Button = CType(gvr.Cells(10).FindControl("DeleteButton"), Button)
If selectCheckBox.Checked Then
selectCheckBox.Checked = False
End If
selectCheckBox.Enabled = False
editButton.Enabled = False
qualificationDropDownList.Enabled = False
qualificationDropDownList.SelectedValue = ""
otherqualificationTextBox.Enabled = False
otherqualificationTextBox.Text = ""
streamsubjectTextBox.Enabled = False
streamsubjectTextBox.Text = ""
universityboardTextBox.Enabled = False
universityboardTextBox.Text = ""
schoolcollegeTextBox.Enabled = False
schoolcollegeTextBox.Text = ""
passingyearTextBox.Enabled = False
passingyearTextBox.Text = ""
percentageTextBox.Enabled = False
percentageTextBox.Text = ""
deleteButton.Enabled = False
End If
Next
End Sub
Private Sub enabledText()
NameTextLabel.Enabled = True
For Each gvr As GridViewRow In QualificationGridView.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim selectCheckBox As CheckBox = CType(gvr.Cells(1).FindControl("SelectCheckBox"), CheckBox)
If selectCheckBox.Checked Then
selectCheckBox.Checked = False
End If
selectCheckBox.Enabled = True
End If
Next
End Sub
Private Sub ChangeCommandStatus(ByVal saveStatus As Integer)
If saveStatus = 1 Then
SaveButton.Enabled = True
UpdateButton.Enabled = False
CancelButton.Enabled = True
ElseIf saveStatus = 2 Then
SaveButton.Enabled = False
UpdateButton.Enabled = True
CancelButton.Enabled = True
Else
SaveButton.Enabled = False
UpdateButton.Enabled = False
CancelButton.Enabled = False
End If
End Sub
Sub findAndColorRowInGridView()
'Ye procedure gridview ka row ko yellow color karta hai jab type kiya hua text ko gridview me find kar leta hai.
For Each gvr As GridViewRow In GridView1.Rows
Dim keyValue As LinkButton = DirectCast(gvr.Cells(1).Controls(0), LinkButton)
If keyValue.Text = Session("keyValue") Then
GridView1.Rows(gvr.RowIndex).BackColor = Drawing.Color.Yellow
Else
GridView1.Rows(gvr.RowIndex).BackColor = Drawing.Color.Transparent
End If
Next
End Sub
Private Sub MesgBox()
Session("appName") = "PersonQualificationDetail.aspx"
Response.Redirect("Message.aspx")
End Sub
End Class
This error is thrown when you click on your command and the Page_load is being ran again, in a normal life cycle will be Page_Load -> Click on Command -> Page_Load (again) -> Process ItemCommand Event.
Also, add this
<%@ Page EnableEventValidation="false" %>
Hope it helps.
If my solution works for you, please mark it as answer! It will help others.
Get more information: http://codemovement.pk
The problem is that ASP.NET does not get to know about this extra or removed listitem. You got an number of options (listed below):
Disable eventvalidation (bad idea, because you lose a little of security that come with very little cost).
Use ASP.NET Ajax UpdatePanel. (Put the listbox in the Updatepanel and trigger a update, if you add or remove listbox. This way viewstate and related fields get updates and eventvalidation will pass.)
Forget client-side and use the classic postback and add or remove the listitems server-side
Please use update panel in your case and it will solve your problem. if you want I can send you some working example of update panel.
I hope this helps.
If my solution works for you, please mark it as answer! It will help others.
Get more information: http://codemovement.pk
Member
8 Points
41 Posts
Error-Failed to load viewstate. I am using 2 gridview.
Oct 17, 2016 03:10 PM|vikas251074|LINK
I am using 2 gridview.
One gridview display list of employees and
other gridview is used for entry of education qualifications.
My application works successfully for displaying records of education qualification of employees.
When I click on an one employee in 1st gridview, it displays qualifications in 2nd gridview.
The problem occurs when I save qualification of 1 employee and display successful message in another form and then return to same form for entry of 2nd employee, it gives above mentioned error.
I have to run program every time for entry of qualifications of each employee. Presently my program is in developmental stage and I am checking my program for every data entry.
Note: This error comes after saving qualifications of any 1 employee and after clicking any command button.
Please consider my problem.
Vikas
Application Developer
Contributor
2340 Points
807 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 17, 2016 03:22 PM|codemovement.pk|LINK
One Simple solution for said problem is
If above solution not works then I would suspect that the
Get more information: http://codemovement.pk
Thanks,
Member
8 Points
41 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 18, 2016 01:58 PM|vikas251074|LINK
I added EnableViewState="false" in following line
After then on every clicking I am getting following error message.
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Vikas
Application Developer
Member
8 Points
41 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 18, 2016 02:02 PM|vikas251074|LINK
I am giving my code as below
Vikas
Application Developer
Contributor
2340 Points
807 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 18, 2016 03:02 PM|codemovement.pk|LINK
You have code in you Page_Load event so add this
This error is thrown when you click on your command and the Page_load is being ran again, in a normal life cycle will be Page_Load -> Click on Command -> Page_Load (again) -> Process ItemCommand Event.
Also, add this
Hope it helps.
Get more information: http://codemovement.pk
Thanks,
Member
8 Points
41 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 19, 2016 09:22 AM|vikas251074|LINK
My problem is solved with this option
I found a security note in using this option and suggested for use of 'RegisterForEventValidation'.
So how can I use this in place of 'EnableEventValidation="false"'
Vikas
Application Developer
Contributor
2340 Points
807 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 19, 2016 12:48 PM|codemovement.pk|LINK
Hi Vikas,
The problem is that ASP.NET does not get to know about this extra or removed listitem. You got an number of options (listed below):
Please use update panel in your case and it will solve your problem. if you want I can send you some working example of update panel.
I hope this helps.
Get more information: http://codemovement.pk
Thanks,
Member
8 Points
41 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 19, 2016 01:51 PM|vikas251074|LINK
Thankyou sir. I like this answer.
Vikas
Application Developer
Contributor
2340 Points
807 Posts
Re: Error-Failed to load viewstate. I am using 2 gridview.
Oct 19, 2016 02:09 PM|codemovement.pk|LINK
If that help then mark it as answer so it is beneficial for others too.
Get more information: http://codemovement.pk
Thanks,