Login

How do I set up my own submit button for a form?

Versions: n/a, FAQ number: 121, Old FAQ number: 944

You can set up a submit button with the following code:

Add a global property for the class:

private bool    _formIsPosted = false;

Add some submit functionality in the aspx/ascx file:

<asp:Button Runat="server" OnClick="Send_Click" Text="Send" />

Add an event handler to set status about the form being posted:

protected void Send_Click(object sender, System.EventArgs e)
{
   _formIsPosted = true;
}

Change the Page_PreRender method so that it checks for _formIsPosted instead of form.IsPosted (change all locations), for instance:

if (form.IsPosted)

should be

if (_formIsPosted)

Your form should now act as it did before, but the default button will still appear after the form has been posted. To solve this you have to set FormProperty.HideDefaultButtons = true:

  private void InitializeComponent()
  {
   ...
   this.Init += new System.EventHandler(this.Page_Init);
   ...
  }

  private void Page_Init(object sender, System.EventArgs e)
  {
   PropertyForm form = FormProperty.InnerProperty as PropertyForm;

   if (form == null)
    return;

   form.HideDefaultButtons = true;
  }

EPiTrace logger