如何在asp.net页面中添加javascript内容
我试图在我的网页中添加一个非常简单的sage支付墙,当我导入脚本时,它似乎没有调用js脚本。我是asp.net新手,不知道如何执行脚本块,我也在C#中使用代码隐藏。这是我用于事务处理的非常简单的asp.net代码如何在asp.net页面中添加javascript内容,javascript,c#,asp.net,Javascript,C#,Asp.net,我试图在我的网页中添加一个非常简单的sage支付墙,当我导入脚本时,它似乎没有调用js脚本。我是asp.net新手,不知道如何执行脚本块,我也在C#中使用代码隐藏。这是我用于事务处理的非常简单的asp.net代码 <%@ Page Language="C#" Inherits="MG_CreditCard_Authenticator_1.Default" %> <!DOCTYPE html> <html> <head runat="serv
<%@ 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>
我已经尝试了所有我能在网上找到的解决方案,但是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>
PayJS(['PayJS/UI'],//正在加载UI模块。。。
函数($UI){//…并将其分配给变量
$UI.Initialize({
elementId:“paymentButton”,
//标识符(无键!):
clientId:“myClientId”//https://developer.sagepayments.com/user/register
商品信息:“99999999997”,
//auth,稍后介绍:
authKey:“ABCD=”,
salt:“DEFG=”,
//配置:
requestType:“payment”、//或“vault”将卡标记化以备以后使用
金额:“1.00”,
订单号:“发票12345”,
//便利性:
addFakeData:对,
});
});
更新的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>
违约
点击
PayJS(['PayJS/UI'],//正在加载UI模块。。。
函数($UI){//…并将其分配给变量
$UI.Initialize({
elementId:“paymentButton”,
//标识符(无键!):
clientId:“myClientId”//https://developer.sagepayments.com/user/register
商品信息:“99999999997”,
//auth,稍后介绍:
authKey:“ABCD=”,
salt:“DEFG=”,
//配置:
requestType:“payment”、//或“vault”将卡标记化以备以后使用
金额:“1.00”,
订单号:“发票12345”,
//便利性:
addFakeData:对,
});
});
我认为您不希望ASP按钮回发到codebehind。您可以在这里看到,我刚刚添加了您的脚本和一个id为paymentButton
的按钮,效果很好 我认为您不希望ASP按钮回发到codebehind。您可以在这里看到,我刚刚添加了您的脚本和一个id为paymentButton
的按钮,效果很好 html中没有id为paymentButton
的元素。我有了它,所有发生的事情都是屏幕上的一闪。我确实看到了屏幕上的闪光,但是除了javascript文件不应包含
之外,没有其他内容。您是否在浏览器中使用JS调试器?@ZeroDayBreak如果您将脚本附加到某个asp按钮上,它可能会回发到服务器并导致页面刷新。@xavier否,那么它应该是javascript吗?浏览器中没有任何元素带有idpaymentButton
的html。我有了它,所有发生的事情都是屏幕上的一闪。我确实看到了屏幕上的闪光,但是除了javascript文件不应包含
之外,没有其他内容。您是否在浏览器中使用JS调试器?@ZeroDayBreak如果您将脚本附加到某个asp按钮,它可能会向服务器发回一个帖子,并导致页面刷新。@xavier不,那么它应该是javascript吗?非常感谢,但它仍在闪烁,然后立即退出,它正在执行js脚本,但它只是闪烁了一秒钟。你的HTML现在是什么样子?您是否在其中一个ASP按钮上添加了id?我将在上面更新它,是的,我添加了,只需单击它即可将type=“button”
添加到
元素中<代码>点击哇,非常感谢Stephen,解决了这个问题。我是网络开发新手,你很耐心,很有帮助,再次感谢。添加类型修正了这一点,这是有原因的吗?非常感谢,但它仍然在闪烁,然后立即退出,它正在执行js脚本,但只是闪烁了一秒钟。你的HTML现在是什么样子?您是否在其中一个ASP按钮上添加了id?我将在上面更新它,是的,我添加了,只需单击它即可将type=“button”
添加到
元素中<代码>点击哇,非常感谢Stephen,解决了这个问题。我是网络开发新手,你很耐心,很有帮助,再次感谢。添加类型修复了这个问题,有什么原因吗?
<%@ 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>