I have one GridView inside an update panel. Last column of the GridView has a LinkButton (<pre lang="HTML">ID="lnkUpdate"
). This LinkButton is used to Validate a few DropDowns in other Columns of GridView using JavaScript function (Validate(lnkUpdate)). I want to update the Data in a DataBase using this LinkButton. I can successfully update the data in the database if I use OnClick="btnSave_Data_Click" however, I have to remove OnClientClick="return Validate(this)".
Can the experts in the forum help me find a way to keep both of these events. I mean I want to be able to Update the Database as well as Validate the DropDownList.
Thanks in advance
What I have tried:
The code for Validate(lnkUpdate) is:
<script type="text/javascript">
function Validate(lnkUpdate) {
var txtIncident, ddlStatus, ddlReason;
var row = lnkUpdate.parentNode.parentNode;
var controls = row.getElementsByTagName("*");
for (var i = 0; i < controls.length; i++) {
if (controls[i].id.indexOf("txtIncident") != -1) {
txtIncident = controls[i];
}
if (controls[i].id.indexOf("ddlStatus") != -1) {
ddlStatus = controls[i];
}
if (controls[i].id.indexOf("ddlReason") != -1) {
ddlReason = controls[i];
}
}
var message = "";
if (ddlStatus.value == "") {
message += "Please select Status";
} else if ((ddlStatus.value == "Make") && (ddlReason.value == "")) {
message += "Please select Reason";
} else if ((ddlStatus.value == "Miss") && (ddlReason.value == "")) {
message += "Please select Reason";
} else if (
((ddlStatus.value == "Miss") && (ddlReason.value == "Data Availablility: Customer") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Availablility: Dell Other") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Availablility: Dell Reporting Team") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Availablility: Vendor") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Integrity: Customer") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Integrity: Dell Other") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Integrity: Dell Reporting Team") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Data Integrity: Vendor") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Duplicate Instance") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "External Factors") && (txtIncident.value == ""))
|| ((ddlStatus.value == "Miss") && (ddlReason.value == "Report Modifications: Customer") && (txtIncident.value == ""))
) {
message += "Please enter Incident#";
} else {
}
if (message != "") {
alert(message);
return false;
}
return true;
}
</script>
and the code for btnSave_Data_Click is:
Protected Sub btnSave_Data_Click(sender As Object, e As EventArgs) Handles btnSave_Data.Click
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp_Insrt_Updt_Rcrd"
cmd.Parameters.AddWithValue("@Report_Date", Today())
cmd.Parameters.AddWithValue("@Name", "")
cmd.Parameters.AddWithValue("@Report_Time", "")
cmd.Parameters.AddWithValue("@Type", "")
cmd.Parameters.AddWithValue("@Effort", "")
cmd.Parameters.AddWithValue("@Account", "")
cmd.Parameters.AddWithValue("@Method", "")
cmd.Parameters.AddWithValue("@Format", "")
cmd.Parameters.AddWithValue("@Status", "")
cmd.Parameters.AddWithValue("@Reason", "")
cmd.Parameters.AddWithValue("@Incident", "")
cmd.Parameters.AddWithValue("@Action", "")
cmd.Parameters.AddWithValue("@Designation", "")
cmd.Parameters.AddWithValue("@Location", "")
cmd.Parameters.AddWithValue("@Support_Region", "")
cmd.Parameters.AddWithValue("@Badge", "")
cmd.Parameters.AddWithValue("@DateTime_IST_India", "")
cmd.Parameters.AddWithValue("@DateTime_CST_Round_Rock", "")
cmd.Parameters.AddWithValue("@DateTime_MST_Cyberjaya", "")
cmd.Parameters.AddWithValue("@DateTime_GMT_Casablanca", "")
cmd.Parameters.AddWithValue("@Week_Working_Day_Number", "")
cmd.Parameters.AddWithValue("@Month_Working_Day_Number", "")
cmd.Parameters.AddWithValue("@NT_Login", "")
cmd.Parameters.AddWithValue("@Report_UID", Today() & "Finally_03")
Dim dt As DataTable = New DataTable
Dim con As SqlConnection = New SqlConnection(strConnString)
Dim sda As SqlDataAdapter = New SqlDataAdapter
cmd.Connection = con
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
End Sub