0

I am new in Asp.Net Webforms. In a asp:Imagebutton, when this button is clicked, application has to call a method "VerifyBlankFields" of a asp:View. If everything is ok, it has to show a confirmation screen to user with a date of a field. If user accept it by clicking in Ok button, application has to call another method to finish the process.

In Webforms, I tried to use:

<asp:ImageButton ID="GenerateProcessBtn" runat="server" ImageUrl="~/img/generateProcess.png"
             ToolTip="Generate Process" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
             CssClass="icon" TabIndex="2" 
             OnClick="VerifyFields()" 
             OnClientClick="if ( ! ConfirDate()) return false;" />

C#

private bool VerifyFields()
{
    //Code here
    return true; //Just example.
}
public string ConfirmDate()
{
    return string.Format("return confirm('Confirm date {0}?');", "01/01/1900"); //--> "01/01/1900" just for test. I have to get the date of a specific field in the asp:View.
}
protected void FinishProcess(object sender, ImageClickEventArgs e)
{
    //Code here to finish the process.
}

What should I do?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • Click event should be `OnClick="FinishProcess"`. Possible duplicate of [Stopping onclick from firing when onclientclick is false?](https://stackoverflow.com/questions/19139747/stopping-onclick-from-firing-when-onclientclick-is-false) – Win Aug 04 '17 at 17:47
  • Thank you Win but it doesn't solve my problem because a have to perform a validation before using "return confirm". You got it? – Everton Solon Aug 04 '17 at 18:06
  • Do you want to perform server side validation before fully postback to server? If so, you will need to make an ***Ajax*** call to a ***WebMethod***. [Here](https://stackoverflow.com/a/42679574/296861) is the sample. – Win Aug 04 '17 at 18:20
  • Win, user asked to change the flow and I'll have to make a different validation. Thank you very much for your attention!!! – Everton Solon Aug 07 '17 at 19:14

0 Answers0