I'm using c# and I have two buttons inside gridview to accept and reject.
If the admin clicks on accept button, it will display confirmation message.
If the admin clicks 'OK' it will change the request status in database and I want to refresh the gridview after click 'OK' to disable accepted student.
This is my code but it is not working
This confirmation message to display 'Ok' or 'cancel' by using java script
function ConfirmAccept() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Are you sure Accept?")) {
confirm_value.value = "OK";
//history.go(0);
//window.location.href = window.location.href;
//location.reload(true);
} else {
confirm_value.value = "Cancle";
}
document.forms[0].appendChild(confirm_value);
}
and this button is inside gridview
<asp:TemplateField HeaderText="Request Status">
<ItemTemplate>
<asp:Button ID="Accept" runat="server" CommandName="Accept" Text="Accept" OnClick="RequestStatus" OnClientClick="ConfirmAccept()" />
<asp:Button ID="Reject" runat="server" CommandName="Reject" Text="Reject" OnClick="RequestStatus" OnClientClick="ConfirmReject()" />
</ItemTemplate>
</asp:TemplateField>
and this request status in c#
protected void RequestStatus(object sender, System.EventArgs e)
{
//Get the button that raised the event
Button btn = (Button)sender;
//Get the row that contains this button
GridViewRow row = (GridViewRow)btn.NamingContainer;
//Get the national Id of the row
String nationalID = row.Cells[4].Text;
//get the id of the button user clicked
string buttonId = btn.ID;
string confirmValue = Request.Form["confirm_value"];
String RowRequestStatus;
if (buttonId == "Accept" )
{
if (confirmValue == "OK")
{
// TextBox1.Text = "accept";
// this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You sure accept " + row.Cells[4].Text + "!')", true);
RowRequestStatus = "Accept";
getdataobj.changeRequestStatue(RowRequestStatus, nationalID);
btn.PostBackUrl = "~/Admin.aspx";
}
}
else if (buttonId == "Reject")
{
if (confirmValue == "OK")
{
// this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You sure Reject " + row.Cells[4].Text + " !')", true);
RowRequestStatus = "Reject";
getdataobj.changeRequestStatue(RowRequestStatus, nationalID);
}
}
}