Problem to show alert box when click submit button

In the code behind, I have the code below when pressing the submit button to show the alert box.

ScriptManager.RegisterStartupScript(this, GetType(), “alertMessage”, “alert(‘Message to user!!!’);”, true);
this.SaveFormData(this.FormData, true);
SubmitToWorkflow();

The problem is the alert box will not be shown and continue finish the workflow when pressing the submit button.
But if I remove “SubmitToWorkflow()” from the code above, the alert box can be shown.

Is there any way to show alert box before it run “SubmitToWorkflow()” when pressing the submit button?

If you are using FormDesigner, the default page validation at submit button event is managed by WorkflowGen page and you cannot interrupt the submission.

You need to override WorkflowGen page validation by doing the following:

    //  turn off the HandleSubmitButton flag in the OnPreLoad event, this is the only place where it is allowed.
	protected override void OnPreLoad(EventArgs e)
	{
	    // Turn off before calling base.OnPreLoad(e)
	    HandleSubmitButton = false;
	    
	    base.OnPreLoad(e);
	    
	    // Add your custom events to the submit button
	    submitButton.Click += new EventHandler(MySubmitButton_Click);
	    
	    // Add the validation group constant (Done by WorkflowGen when HandleSubmitButton is true)
	    // It is required in order to have the correct WorkflowGen Behaviour with the required fields.
        submitButton.ValidationGroup = "WFGENPage";
	}

Then you can have your override MySubmitButton_Click event to show the alert and stop submission

protected void MySubmitButton_Click(object sender, EventArgs e)
    {

        //-- this happens after the submit button is clicked. The validate message and the javascript will appear in the next action
       if (some_condition_does_not_match)
       {
               ClientScript.RegisterClientScriptBlock(this.GetType(), "interrupt", "alert('your alert message');", true);
       }
       else
       {
           // Submit to workflowgen
	        SubmitToWorkflow();
       }
       

     }

Hi @kevin.lee,

Yeah, I’m using the FormDesigner.

I do have override the WorkflowGen page validation:

protected override void OnPreLoad(EventArgs e)
{
        IsSessionLess = true;
        
        HandleSubmitButton = false;

        submitButton.Click += new EventHandler(testSubmitButton_Click);
        submitButton.ValidationGroup = "WFGENPage";
        
        base.OnPreLoad(e);
}

But the problem is when I using the code below, the alert box did not show up at all after click the submit button.

protected void testSubmitButton_Click(object sender, EventArgs e)
{
	    if(condition == 1)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 1!!!');", true);
	    }
	    else if(condition == 2)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 2!!!');", true);
	    }
	    
	    this.SaveFormData(this.FormData, true);
	    SubmitToWorkflow();
}

If I remove the “SubmitToWorkflow();” code, the alert box is able to display after click the submit button.

protected void testSubmitButton_Click(object sender, EventArgs e)
{
	    if(condition == 1)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 1!!!');", true);
	    }
	    else if(condition == 2)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 2!!!');", true);
	    }
	    
	    this.SaveFormData(this.FormData, true);
	   // SubmitToWorkflow();
}

I would like to know if there any possible method to solve the problem above.

Hi,

You should have your

this.SaveFormData(this.FormData, true);
SubmitToWorkflow();

inside your if statement. In your code regardless of what situation it will run submittoWorkflow() meaning WorkflowGen page will not return back to you page and submit back to WFG engine.

The logic is if you interrupt at submission your if statement is to control when to call submittoworkflow().

So you should have

protected void testSubmitButton_Click(object sender, EventArgs e)
{
	    if(condition == 1)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 1!!!');", true);
	    }
	    else if(condition == 2)
	    {
	        ScriptManager.RegisterStartupScript(this, GetType(), "a1", "alert('Condition 2!!!');", true);
	    }
	    else
        {
	       this.SaveFormData(this.FormData, true);
	       SubmitToWorkflow();
        }
}

Hi @kevin.lee,

Thanks for your explanations.

For my situation, SubmitToWorkflow() will always run regardless what condition it is.

I just want to know is there any other possible method so that it will pop up message base on condition, then it will straight complete that workflow.

Hi @wing_hou just want to be clear. You said

“For my situation, SubmitToWorkflow() will always run regardless what condition it is.”

Do you mean you need the SubmitToWorkflow() to always run, i.e. you want the javascript alert but still submit right after?

If this is the case, you have to do a client side trigger to your javascript alert (on client click on the submit button to run the javascript and show the prompt) and followed by the normal WFG submission.

Once you call SubmitToWorkflow() in code behind basically it means WFG page will not render the page on screen but redirect the page back to the workflow and leave/complete the eformASPX application.