title: Two panels with forms that switch based on radio button
body: <p>I have 2 panels that each have a form. They are hidden at first, and a radio button selection will make 1 panel visible. One is for credit card payments, and the other is for echecks. The code works for this, but there is one glitch. The echeck option first clears the form on submission and then will submit the form in the second click.</p>
  
  <p>How can I get the 2nd panel (checks) to submit the form when it is selected by the radio button for the first time? Does it have to do with Page.IsPostBack or maybe how my if statements are in the Page_Load section?</p>
  
  <p>Here are the 2 radio buttons</p>
  
  <pre><code>  &lt;asp:RadioButton ID="RadioButton1" runat="server"  GroupName="RbPayment" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Credit Card" Checked="True" AutoPostBack="True" /&gt; 
    &lt;asp:RadioButton ID="RadioButton2" runat="server" GroupName="RbPayment" OnCheckedChanged="RadioButton2_CheckedChanged" Text="Check" AutoPostBack="True" /&gt;
  </code></pre>
  
  <p>This is where I have the 2 panels and forms</p>
  
  <pre><code>&lt;asp:Panel ID="PanelCard" runat="server" Visible="false" OnLoad="RadioButton1_CheckedChanged"&gt;
         &lt;%--Form here--%&gt;
         &lt;asp:Button ID="Button1" runat="server" Text="Submit Payment" ClientIDMode="Static" CssClass="formbutton" /&gt;
  &lt;/asp:Panel&gt;
  &lt;asp:Panel ID="PanelCheck" runat="server" Visible="false" OnLoad="RadioButton1_CheckedChanged"&gt;
         &lt;%--Form here--%&gt;
         &lt;asp:Button ID="Button1" runat="server" Text="Submit Payment" ClientIDMode="Static" CssClass="formbutton" /&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>I have this code to swap between the panels when a radio button is selected</p>
  
  <pre><code>protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
      {
          if (RadioButton1.Checked)
          {
              PnlCard.Visible = true;
              PnlCheck.Visible = false;
          }
  
          if (RadioButton2.Checked)
          {
              PnlCard.Visible = false;
              PnlCheck.Visible = true;
          }
  
      }
  
      protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
      {
          if (RadioButton1.Checked)
          {
              PnlCard.Visible = true;
              PnlCheck.Visible = false;
          }
  
          if (RadioButton2.Checked)
          {
              PnlCard.Visible = false;
              PnlCheck.Visible = true;
          }
      }
  </code></pre>
  
  <p>This is where I think the problem is but I am not sure what needs to be fixed</p>
  
  <pre><code>  protected void Page_Load(object sender, System.EventArgs e)
      {
          if (!Page.IsPostBack)
          {
              BtnSubmitCard.PostBackUrl = "https://secure2.authorize.net/gateway/transact.dll";
              //Other code here for the form
              }
  
          if (PnlCard.Visible == true)
          {
              BtnSubmitCard.PostBackUrl = "https://secure2.authorize.net/gateway/transact.dll";
              //Other code here for the form
          }
  
          if (PnlCheck.Visible == true)
          {
              BtnSubmitCheck.PostBackUrl = "https://secure2.authorize.net/gateway/transact.dll";
             //Other code here for the form
          }
      }
  </code></pre>