我有2个面板,每个面板都有一个表格。它们首先被隐藏,选择单选按钮将使1个面板可见。一个是信用卡支付,另一个是echecks。代码适用于此,但有一个小故障。 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
}
}
答案 0 :(得分:2)
您的代码方似乎是可靠的,但正如第一条评论所暗示的那样,这确实是一个回发问题。您需要为每个部分使用UpdatePanel来动态更改可见性,如下所示:
<?php
//call array function to walk on each element of $v array and convert it to numeric value
array_walk($v, 'convert_to_num');
function convert_to_num(&$value, $key) {
$value = $value * 1;
}
var_dump($v);
?>
或者,您可以使用两个单独的更新面板而不是一个大面板,只需将每个标准面板包装在更新面板中即可。这将减少每次部分回发的数据量。
编辑:如果它不存在,您还需要在页面中添加脚本管理器。