从另一个页面更新页面而不刷新页面
Updating a page from another page without refreshing the page
我有两个网页写在VisualBasic.Net:
- Upload.aspx
- Default.aspx
默认页面中有一个 link 以不同的 window 打开上传页面。
在上传 window 我上传了一个文件,我想在文本框中显示这个文件的名称,而文本框又在默认页面的网格视图中。
我想我想要一个不会导致默认页面刷新的异步进程,但我不知道该怎么做。
我为您创建了一个非常简单的示例。这是第一页的代码(假设您的 Default.aspx):
<html>
<head>
<script>
function ow() {
window.open('w2.html');
}
function update(updatestr) {
document.getElementById('update').innerHTML = updatestr;
}
</script>
</head>
<body>
<a href="#" onclick="ow()">open window</a>
<div id="update"></div>
</body>
</html>
此页面包含一个 link,它会打开一个新的 window(这将是您的 Upload.aspx 页面)。它还包含一个称为更新的简单函数,它将参数值作为 div html 内容。
这是第二页的代码(您的Upload.aspx喜欢):
<html>
<head>
<script>
function update() {
window.opener.update(document.getElementById('txt').value);
}
</script>
</head>
<body>
<input type="text" id="txt" />
<input type="button" value="Update" onclick="update()"/>
</body>
</html>
此页面包含一个文本框和一个按钮。单击按钮后,文本框的内容将出现在第一页的 div 中。你可以在你的情况下做类似的事情。
我已经为你准备了一个工作 demo。
我有两个网页写在VisualBasic.Net:
- Upload.aspx
- Default.aspx
默认页面中有一个 link 以不同的 window 打开上传页面。
在上传 window 我上传了一个文件,我想在文本框中显示这个文件的名称,而文本框又在默认页面的网格视图中。
我想我想要一个不会导致默认页面刷新的异步进程,但我不知道该怎么做。
我为您创建了一个非常简单的示例。这是第一页的代码(假设您的 Default.aspx):
<html>
<head>
<script>
function ow() {
window.open('w2.html');
}
function update(updatestr) {
document.getElementById('update').innerHTML = updatestr;
}
</script>
</head>
<body>
<a href="#" onclick="ow()">open window</a>
<div id="update"></div>
</body>
</html>
此页面包含一个 link,它会打开一个新的 window(这将是您的 Upload.aspx 页面)。它还包含一个称为更新的简单函数,它将参数值作为 div html 内容。
这是第二页的代码(您的Upload.aspx喜欢):
<html>
<head>
<script>
function update() {
window.opener.update(document.getElementById('txt').value);
}
</script>
</head>
<body>
<input type="text" id="txt" />
<input type="button" value="Update" onclick="update()"/>
</body>
</html>
此页面包含一个文本框和一个按钮。单击按钮后,文本框的内容将出现在第一页的 div 中。你可以在你的情况下做类似的事情。
我已经为你准备了一个工作 demo。