因此,我有一个可以创造奇迹的PayPal表单。但是,我现在需要添加一个优惠券字段,其中有人可以输入代码,并根据后端回复进行减少。阻止提交表单的Asp.NET按钮
这一切都很好用,但在检查之前添加选项以知道时遇到了问题,您的代码是否有效。目前,我的形式(一次简化的)看起来是这样的:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"
id="payPalForm" runat="server">
<asp:TextBox runat="server" ID="txtCode" />
<asp:Button Text="Validate" OnClick="ValidateDiscount" runat="server" />
<asp:Label ID="txtDesc" runat="server" />
<input type="submit" name="Submit" value="Pay up!" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
...
</form>
随着具有功能后端:
protected void ValidateDiscount(object sender, EventArgs e)
{
this.txtDesc.Text = "fetch from database using: " + txtCode.Text;
}
我的问题是,wheneve我点击验证按钮,提交表单和我最终在Paypal网站上。我先用preventDefault()来使用Jquery,但实际上阻止了我的服务器端函数被触发。我也尝试过使用标准<button>
或<input type='button'>
标签,但我无法启动它来激活我的服务器端功能。
有什么办法让Validate按钮不提交表单,或者我应该从表单中删除操作,并在点击提交按钮时手动提交表单?
您的表单将发布到paypal,因为这是您为其设置的操作。你有很多选择。当您发现折扣有效时,您可以尝试从C#中的ValidateDiscount函数重定向到paypal。 – Shockwave