【发布时间】:2016-04-13 10:29:48
【问题描述】:
我有 2 个面板,每个面板都有一个表单。它们最初是隐藏的,单选按钮选择将使 1 个面板可见。一种用于信用卡支付,另一种用于电子支票。该代码适用于此,但有一个故障。 echeck 选项首先在提交时清除表单,然后将在第二次单击时提交表单。
第一次被单选按钮选中时,如何让第二个面板(检查)提交表单?它是否与 Page.IsPostBack 或我的 if 语句在 Page_Load 部分中的方式有关?
这是 2 个单选按钮
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="RbPayment" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Credit Card" Checked="True" AutoPostBack="True" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="RbPayment" OnCheckedChanged="RadioButton2_CheckedChanged" Text="Check" AutoPostBack="True" />
这是我有 2 个面板和表单的地方
<asp:Panel ID="PanelCard" runat="server" Visible="false" OnLoad="RadioButton1_CheckedChanged">
<%--Form here--%>
<asp:Button ID="Button1" runat="server" Text="Submit Payment" ClientIDMode="Static" CssClass="formbutton" />
</asp:Panel>
<asp:Panel ID="PanelCheck" runat="server" Visible="false" OnLoad="RadioButton1_CheckedChanged">
<%--Form here--%>
<asp:Button ID="Button1" runat="server" Text="Submit Payment" ClientIDMode="Static" CssClass="formbutton" />
</asp:Panel>
我在选择单选按钮时,我有此代码在面板之间交换
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;
}
}
这是我认为问题所在,但我不确定需要修复什么
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
}
}
【问题讨论】:
-
这听起来像是一个
IsPostBack问题。也许您可以使用 UpdatePanel 来执行此操作,而不是执行部分回发 -
这些表单是服务器端元素吗? asp.net 每页只能处理 1 个服务器端表单。这会导致您的问题吗?
-
@MethodMan 谢谢,我刚试过,但它不起作用,因为我使用了一些“输入”字段(由于支付网关的安全性)。
-
@Sami 两种表格都正确提交。只是在页面加载时,第二个面板的提交按钮会在第一次单击时清除表单。在第二次点击时,它提交表单就好了。
-
您是否已启用 viewstate 设置为 true..?或许您可以将值存储在会话或视图对象中并在该负载上重新分配