Form designer: Add a hidden field dynamically

This example shows how to add a hidden field in the form dynamically at the runtime.

Add the following code to the form’s .NET code:

protected override void OnPreLoad(EventArgs e){ Label newField = new Label();
 newField.ID = "MY_HIDDEN_FIELD"; newField.Text = "its hidden value"; newField.Visible = false; this.form1.Controls.Add(newField); base.OnPreLoad(e);}