I have a grid view consisting of a text box and drop down for every row in the grid view. I want a confirmation dialog to show when the user enters a value in the text box if it does not match the value of a corresponding label for each row in which this is true.
Front End
<asp:TemplateField HeaderText="Payment Amount">
<ItemTemplate>
<asp:Label ID="lblSuggestedAmount" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actual Payment Amount">
<ItemTemplate>
<asp:TextBox ID="txtbxActualAmount" Visible="true" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="For Rental Month">
<ItemTemplate>
<asp:DropDownList ID="ddlPaymentMonth" Visible="true" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
What I found to work on my local machine when debugging was System.Windows.Forms.MessageBox.Show()
but when I upload my project to my IIS the prompt does not appear.
Code Behind
TextBox actualAmount = (TextBox)gvPayments.Rows[i].FindControl("txtbxActualAmount");
Label suggestedAmount = (Label)gvPayments.Rows[i].FindControl("lblSuggestedAmount");
if (Convert.ToDouble(actualAmount.Text) != Convert.ToDouble(suggestedAmount.Text)) {
System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Some payments have actual payment amounts greater than the suggested amount. Is this correct?", "Warning",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning,
System.Windows.Forms.MessageBoxDefaultButton.Button1,
System.Windows.Forms.MessageBoxOptions.ServiceNotification);
if (dr == System.Windows.Forms.DialogResult.No) {
return;
} else {
actualAmount.BackColor = Color.White;
}
}
I understand that because the dialog shows up on client side, where the code is run that the dialog is showing up on the server, and not on the clients browser.
From reading other similar questions I also understand I need to achieve this with JavaScript.
I imagine I will attach an OnClick
event to my update/submit button but will the javascript be able to cycle row through row of my gridview, compare the Label.text
and the TextBox.Text
and set that text boxes background color to yellow and display my dialog? And then will it know to continue with the rest of the code-behind execution once the user has clicked ok?