我得到了一个项目,其中以某种方式从另一个 aspx.page 调用了一个方法。我想知道这是如何工作的。
例如,在我的 Foo.aspx 中,我得到了这个:
<script runat="server">
Sub ShowHint()
some code
End Sub
</script>
在 Bar.aspx 我得到了这个:
<script runat="server">
ShowHint()
</script>
但这怎么能行呢?我不明白。
您可以使用 JavaScript (AJAX) 从不同的页面获取数据。使用 jQuery Load 函数很容易做到。
您还可以定义类,您可以在其中定义可以从每个网页调用的函数的子项。
你项目里面的网页是吗?
一个简单的例子:我有一个文件 test.aspx,我想从 test2.apsx 加载一些数据。要加载数据,我使用 jQuery。
这是 test.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//$("#presenter").load("test2.aspx" ... = loads the content of test2.aspx into the div with id = presenter
//$("#presenter").load("test2.aspx #content" ... = loads onlay the content of the div with id = content from text2.aspx
//{ message01: "Hello", message02: "world" } = are the paramter I pass to test2.aspx
$("#presenter").load("test2.aspx #content", { message01: "Hello", message02: "world" }, function () {
//here you can place code which will run after the load is completet
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="presenter"></div>
</form>
</body>
</html>
这是 test2.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="test2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="content" runat="server">
</div>
</form>
和 test2.asp 中的代码
Partial Class test2
Inherits System.Web.UI.Page
Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
Dim msg01 As String = Request("message01")
Dim msg02 As String = Request("message02")
Me.content.InnerHtml = msg01 & " " & msg02
End Sub
End Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句