I have a donation form that contains an update panel that contains a dropdown for predetermined amounts plus the "Other" option". When "Other" is selected the dropdown has triggered the partial postback and renders the update panel with the additional "Other" textbox for the amount. Outside this update panel I have a additional server control form fields such as textboxes and a button for submission.
The bug I run into is when "Other" is selected the button "onclick" event fails to fire a full postback.
Example:
<asp:UpdatePanel ID="updatePanelAmount" runat="server">
<ContentTemplate>
<table style="width: 500px;">
<tbody>
<tr>
<th style="width: 200px;"><asp:Label ID="lblAmount" runat="server" CssClass="required" Text="Donation Amount: " /></th>
<td>
<asp:DropDownList ID="selAmount" runat="server" />
<asp:CustomValidator ID="valDonationAmount" runat="server" ControlToValidate="selAmount" ErrorMessage="Donation Amount" Display="None" />
</td>
</tr>
</tbody>
</table>
<asp:Panel ID="panelOther" runat="server" Visible="false">
<table style="width: 500px;">
<tbody>
<tr>
<th style="width: 200px;"><asp:Label ID="lblOther" runat="server" Text="Other Amount: " /></th>
<td>
$<asp:TextBox ID="txtOther" runat="server" />
<asp:RequiredFieldValidator ID="valOther" runat="server" ControlToValidate="txtOther" Display="None" ErrorMessage="Other Amount" Enabled="false" />
<asp:RegularExpressionValidator ID="valOtherExpress" runat="server" ControlToValidate="txtOther" Display="None" ErrorMessage="Other Amount: Invalid" ValidationExpression="[1-9][0-9]+(\.[0-9]{2})?" Enabled="false" />
</td>
</tr>
</tbody>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<ctl:CreditCardForm ID="ctlCreditCardForm" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Donate" />
EDIT: Posting the code-behind might make is easier for everyone
public partial class _Default : System.Web.UI.Page
{
private ArrayList _donations;
protected void Page_Init(object sender, EventArgs e)
{
valDonationAmount.ServerValidate += new ServerValidateEventHandler(valDonationAmount_ServerValidate);
selAmount.AutoPostBack = true;
selAmount.SelectedIndexChanged += new EventHandler(selAmount_SelectedIndexChanged);
updatePanelAmount.UpdateMode = UpdatePanelUpdateMode.Conditional;
updatePanelAmount.ChildrenAsTriggers = true;
btnSubmit.Click += new EventHandler(btnSubmit_Click);
}
void selAmount_SelectedIndexChanged(object sender, EventArgs e)
{
if (selAmount.SelectedItem.Text == "Other")
{
panelOther.Visible = true;
valOther.Enabled = true;
valOtherExpress.Enabled = true;
}
else
{
panelOther.Visible = false;
valOther.Enabled = false;
valOtherExpress.Enabled = false;
}
}
void valDonationAmount_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = true;
if (args.Value == "0")
{
args.IsValid = false;
}
}
void btnSubmit_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
_donations = new ArrayList();
double[] donations = new double[] { 20.00, 50.00, 100.00, 250.00, 500.00 };
_donations.AddRange(donations);
if (!IsPostBack)
{
foreach (Double d in _donations)
{
selAmount.Items.Add(new ListItem(String.Format("{0:c}", d), String.Format("{0:c}", d)));
}
selAmount.Items.Insert(0, new ListItem("Select Donation Amount","0"));
selAmount.Items.Add(new ListItem("Other", "Other"));
}
}
}