使用jQuery将参数从一个asp.net页面传递到另一个asp.net页面
我需要使用jQuery将4个参数(3个字符串和一个逗号分隔列表)从一个ASP.NET页面传递到另一个ASP.NET页面。目标页面应该作为一个单独的窗口启动,它可以与以下jQuery代码片段配合使用:使用jQuery将参数从一个asp.net页面传递到另一个asp.net页面,asp.net,jquery,Asp.net,Jquery,我需要使用jQuery将4个参数(3个字符串和一个逗号分隔列表)从一个ASP.NET页面传递到另一个ASP.NET页面。目标页面应该作为一个单独的窗口启动,它可以与以下jQuery代码片段配合使用: $('#sourcePageBtn').click(function(){ window.open("destinationPage.aspx"); return false; }); 如何将参数传递到目标页面?我试图避免使用查询字符串来传递参数,因为: 我不想在目标窗口中显示url参
$('#sourcePageBtn').click(function(){
window.open("destinationPage.aspx");
return false;
});
如何将参数传递到目标页面?我试图避免使用查询字符串来传递参数,因为:
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e)
{
//Creating dynamic asp controls here
}
</script>
受保护的无效页面加载(对象src、事件参数e)
{
//在此处创建动态asp控件
}
我对脚本部分Page_Load中的参数的特殊需求源于这样一个事实,即我正在Page_Load中创建一些依赖于这些参数的动态图表控件
干杯初始想法(创建解决方案之前)
- -启动请求、传递参数、获取响应
- -这是从主窗口访问/影响弹出窗口DOM的方式
- 主脚本打开一个弹出窗口(如果它不存在)
- 主脚本等待弹出窗口完全初始化
- 主脚本将参数(使用AJAX)发布到另一个页面(发送请求)
- 主脚本接收响应并将其显示在弹出窗口中
id=sourcePageBtn
此示例在POST发生时传递两个键/值对(仅举个例子)。您将在此处传递所选的键/值对
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
</head>
<body>
<a id="sourcePageBtn" href="javascript:void(0);">click to launch popup window</a>
<script>
$(function() {
$('#sourcePageBtn').click( function() {
// Open popup window if not already open, and store its handle into jQuery data.
($(window).data('popup') && !$(window).data('popup').closed)
|| $(window).data('popup', window.open('popup.html','MyPopupWin'));
// Reference the popup window handle.
var wndPop = $(window).data('popup');
// Waits until popup is loaded and ready, then starts using it
(waitAndPost = function() {
// If popup not loaded, Wait for 200 more milliseconds before retrying
if (!wndPop || !wndPop['ready'])
setTimeout(waitAndPost, 200);
else {
// Logic to post (pass args) and display result in popup window...
// POST args name=John, time=2pm to the process.aspx page...
$.post('process.aspx', { name: "John", time: "2pm" }, function(data) {
// and display the response in the popup window <P> element.
$('p',wndPop.document).html(data);
});
}
})(); //First call to the waitAndPost() function.
});
});
</script>
</body>
</html>
process.aspx.cs(C#-ASP.NET process.aspx页面)
主页脚本将参数发布到的动态服务器页面。
AJAX参数到达集合中。
在本例中,输出以纯文本形式返回,但您可以根据应用程序的要求自定义响应
public partial class process : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
// Access "name" argument.
string strName = Request["name"] ?? "(no name)";
// Access "time" argument.
string strTime = Request["time"] ?? "(no time)";
Response.ContentType = "text/plain";
Response.Write(string.Format("{0} arrives at {1}", strName, strTime));
}
protected override void Render(System.Web.UI.HtmlTextWriter writer) {
// Just to suppress Page from outputting extraneous HTML tags.
//base.Render(writer); //don't run.
}
}
结果将通过原始/主页显示在弹出窗口中。
因此,弹出窗口的内容会被覆盖“[name]到达[时间]”
主要引用:,如果在打开新窗口时保留对它的引用,即
var destWin=window.open(…)
,则可以访问destWin window对象上的变量和方法。或者,您也可以使用窗口从目的地窗口“回过头来”。opener
谢谢。我需要从jQuery按钮点击处理程序启动目标页面,因为我正在收集jQuery按钮点击中几个HTML元素的ID和文本值。其次,我需要启动一个新页面,而不是重定向。window.open()对我来说就是这样,但我认为它不支持类似于POST的行为。我编辑了一个链接,指向jQuery POST示例。我的方向对吗?再次谢谢。你的回答对我很有意义。$.POST()会将控件带到目标页。但是控件返回到源页面。另外,目标页面并不是作为一个单独的页面启动的。我仍然在尝试。代码示例正在进行中…,但是现在有趣的是在主窗口中使用jQuery语法$(元素,上下文)
,并在上下文jQuery访问弹出窗口的DOM并显示仅在弹出窗口中看到的内容时提供弹出窗口的窗口句柄。希望.get和.post也可以用来影响弹出窗口。。。时间会证明一切。解决方案已完成。它会打开一个poupup窗口,并将数据从主页发布到该窗口——该解决方案根据您的要求使用jQuery/AJAX。如果您只是将源代码复制并粘贴到三个文件中,您可以自己运行它。
public partial class process : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
// Access "name" argument.
string strName = Request["name"] ?? "(no name)";
// Access "time" argument.
string strTime = Request["time"] ?? "(no time)";
Response.ContentType = "text/plain";
Response.Write(string.Format("{0} arrives at {1}", strName, strTime));
}
protected override void Render(System.Web.UI.HtmlTextWriter writer) {
// Just to suppress Page from outputting extraneous HTML tags.
//base.Render(writer); //don't run.
}
}