Can I use a .NET user control in my webform?

You can use .NET user controls in webforms. .NET user controls provide the flexibility of separating the content of a webform into different individual sections. Each section is contained in a user control file (.ascx). Since user controls files have their own design and .cs page (code-behind) acting as an independent module, a user control can be reused within different projects. WorkflowGen will recognize all supported WorkflowGen elements within a user control, with certain conditions.

Details

User controls are supported in WorkflowGen.My version 2.1.x or later. When a webform is launched at the pre-render stage, WorkflowGen.My will parse all supported .NET controls on the main .aspx form page, as well as controls within any user control .ascx page. It will then prepare all necessary data columns for the form data (in Simple Mode).

Controls inside a user control file will have the user control ID as a prefix. For example, if a user control ID is named USERCTRL1 and within that control there’s a textbox with an ID named APPROVAL_AMT, then the reference of this textbox will be USERCTRL1.APPROVAL_AMT.

We can also use this notation in WorkflowGen action parameters. For example, we can set/read the value for this APPROVAL_AMT field:

USERCTRL1.APPROVAL_AMT IN 100000

USERCTRL1.APPROVAL_AMT OUT APPROVAL_OUT (process data)

You can also use the wildcard asterisk symbol (*) in case of reference elements in the user control. For example if you need to set everything in USERCTRL1 as required, you can use the FORM_FIELD_REQUIRED parameter:

FORM_FIELD_REQUIRED INUSERCTRL1.\*

However, since a user control does not inherit WorkflowGen.My class, you cannot use any WorkflowGen.My methods within the user control code-behind page. This includes the use of the predefined SubmitButton buttons. To overcome this, you will need to define your methods containing the use of WorkflowGen.My class object or methods on your main aspx.cs page. Then, add a public event handler in your user control so that the main aspx.cs page can instantiate WorkflowGen methods for the event in the user control.

Example for adding a WorkflowGen submit button in a user control:

//----- on default.aspx.cs page ------
// Prepare a method for the user control submit button event 
// that basically triggers SubmitToWorkflow()
void UserCtrl_btnUserCtrlSubmitHandler(string strValue){ 
SubmitToWorkflow(); 
}
// Create a new event handler that captures the button click event from user control
// The user control has an ID called UCTRL on default.aspx page
// In UserCtrl.aspx.cs there is a submit button event handler called
// btnUserCtrlSubmitHandler for an event called OnSubmitButtonClick 
// Once this event is triggered, 
// it will pass the method UserCtrl_btnUserCtrlSubmitHandlerprotected 
void Page_Load(object sender, EventArgs e){
UCTRL.btnUserCtrlSubmitHandler += new UCTRL.OnSubmitButtonClick(UserCtrl_btnUserCtrlSubmitHandler);
}

//----- on UserCtrl.acsx.cs page ------//
// add event declaration for the main default.aspx page 
// this event is triggered when a button control called Button2 is clicked//
// Delegate declarationpublic delegate 
void OnSubmitButtonClick(string strValue);
// Event declaration 
public event OnSubmitButtonClick btnUserCtrlSubmitHandler;
//// in case of the button control Button2 in user control is clicked, 
// it triggers the OnSubmitButtonClick event that references to
// UserCtrl_btnUserCtrlSubmitHandler method on the main page
protected void Button2_Click(object sender, EventArgs e){
if (btnUserCtrlSubmitHandler != null){ 
btnUserCtrlSubmitHandler(string.Empty); 
}
}