gpt4 book ai didi

javascript - 如何在asp.net页面中添加javascript内容

转载 作者:行者123 更新时间:2023-11-28 04:31:59 24 4
gpt4 key购买 nike

我试图在我的网页中添加一个非常简单的圣人支付墙,当我导入脚本时,它似乎没有调用 js 脚本。我是 ASP.NET 新手,不知道如何执行脚本 block ,我也在 C# 中使用代码隐藏。这是我用于事务处理的非常简单的 ASP.NET 代码。

    <%@ Page Language="C#" Inherits="MG_CreditCard_Authenticator_1.Default" %>
<!DOCTYPE html>


<html>

<head runat="server">
<title>Default</title>


</head>



<body>

<form id="form1" runat="server" >
<div id="topLevel" runat="server" margin="100px">
<asp:Label id="InvoiceLable" runat="server" Text="Invoice" />
<asp:TextBox id="InvoiceTextBox" runat="server" TextMode="Password" />
</div>

<div id="secondTopLevel" runat="server" >
<asp:Label id="DateLabel" runat="server" Text="Date"/>
<asp:TextBox id="DateTextBox" runat="server"/>
</div>
<div id="thirdTopLevel" runat="server">
<asp:Button id="button1" runat="server" Text="Finish" OnClick="button1Clicked" />
</div>
<div id="form2" runat="server">

<asp:TextBox id="postInflow" runat="server" Height="200px" Width="400px" ReadOnly="true" TextMode="MultiLine" />
<asp:Button id="genRecipt" runat="server" Text="Generate" OnClick="ACHauth" />

<script type="text/javascript" src="https://www.sagepayments.net/pay/1.0.2/js/pay.min.js"></script>

<!-- <script language="javascript"src='<%=ResolveUrl("PaymentHandler.js")%>' type='text/javascript'</script>
-->

</div>
</form>

</body>
</html>

这是我的 C# 代码背后的代码

using System;
using System.Web;
using System.Web.UI;

namespace MG_CreditCard_Authenticator_1
{

public partial class Default : System.Web.UI.Page
{
String invoiceNumber = "Invoice Number";
//String Date = "";
//String outputData = "";
//int buttonclicks = 0;


public void button1Clicked(object sender, EventArgs args)
{

button1.Text = "Done";
invoiceNumber = InvoiceTextBox.Text;
InvoiceLable.Text = "Invoice Number";
postInflow.Text = "Displaying info for Invoice Number: "+InvoiceTextBox.Text+" made on "+DateTextBox.Text;

Page.ClientScript.RegisterClientScriptInclude("Registration", ResolveUrl("/Users/ShashankMurthy/Projects/MG_CreditCard_Authenticator_1.03/MG_CreditCard_Authenticator_1.03/PaymentHandler.js"));

}

public void GetValue(String key){

var appConfig = System.IO.File.ReadAllText(key);
}
public void ACHauth(object sender, EventArgs args){
}
}
}

我已经尝试了网上能找到的所有解决方案,但 javascript 函数没有被调用。

我为脚本创建的 Javascript 文件

<script type="text/javascript">
PayJS(['PayJS/UI'], // loading the UI module...
function($UI) { // ... and assigning it to a variable
$UI.Initialize({
elementId: "paymentButton",
// identifiers (no keys!):
clientId: "myClientId", // https://developer.sagepayments.com/user/register
merchantId: "999999999997",
// auth, covered later:
authKey: "ABCD==",
salt: "DEFG==",
// config:
requestType: "payment", // or "vault" to tokenize a card for later
amount: "1.00",
orderNumber: "Invoice12345",
// convenience:
addFakeData: true,
});
});
</script>

更新了 asp.net 代码

<%@ Page Language="C#" Inherits="MG_CreditCard_Authenticator_1.Default" %>
<!DOCTYPE html>


<html>

<head runat="server">
<title>Default</title>


</head>



<body>

<form id="form1" runat="server" >
<div id="topLevel" runat="server" margin="100px">
<asp:Label id="InvoiceLable" runat="server" Text="Invoice" />
<asp:TextBox id="InvoiceTextBox" runat="server" TextMode="Password" />
</div>

<div id="secondTopLevel" runat="server" >
<asp:Label id="DateLabel" runat="server" Text="Date"/>
<asp:TextBox id="DateTextBox" runat="server"/>
</div>
<div id="thirdTopLevel" runat="server">
<asp:Button id="button1" runat="server" Text="Finish" OnClick="button1Clicked" />
</div>
<div id="form2" runat="server">

<asp:TextBox id="postInflow" runat="server" Height="200px" Width="400px" ReadOnly="true" TextMode="MultiLine" />

<script type="text/javascript" src="https://www.sagepayments.net/pay/1.0.2/js/pay.min.js"></script>

<button id="paymentButton">
Click
</button>

<script type="text/javascript">
PayJS(['PayJS/UI'], // loading the UI module...
function($UI) { // ... and assigning it to a variable
$UI.Initialize({
elementId: "paymentButton",
// identifiers (no keys!):
clientId: "myClientId", // https://developer.sagepayments.com/user/register
merchantId: "999999999997",
// auth, covered later:
authKey: "ABCD==",
salt: "DEFG==",
// config:
requestType: "payment", // or "vault" to tokenize a card for later
amount: "1.00",
orderNumber: "Invoice12345",
// convenience:
addFakeData: true,
});
});
</script>




</div>



</form>

</body>
</html>

最佳答案

我认为您不希望 ASP 按钮回发到代码隐藏。你可以在这里看到https://jsfiddle.net/ax67cpjt/我刚刚添加了您的脚本和一个带有 id paymentButton 的按钮,它工作正常。

关于javascript - 如何在asp.net页面中添加javascript内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com