JavaScript(AJAX)を使用して別のページからデータを取得できます。 jQuery Load関数を使用するのは簡単です。
また、すべてのWebページから呼び出すことができる関数のサブ定義を定義するクラスを定義することもできます。
あなたのプロジェクト内のウェブページはありますか?
簡単な例:私は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>
そして、私が得た
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
これを行う方法は簡単ですか? –
私はjavascriptクラスを定義し、そこから関数を呼び出すことができますが、これを2つの.aspxページでどうやって行うことができるのでしょうか?その1つの.aspxページはヘルパークラスのように動作するようです。空白のページで、タグのvbコードのみを含んでいます。 –