如何在不同的窗口中打开.aspx页面 [英] how to open .aspx page in different window
本文介绍了如何在不同的窗口中打开.aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在不同的窗口中打开网页,并在页面加载时将值从javascript传递到c#
< JavaScript >
函数open_win()
{
var s = document.getElementById(txtQty);
window.open(../ Stock / IPurchaseDetail.aspx,_ blank,toolbar = yes,location = yes,directories = no,status = no,menubar = yes,scrollbars = yes,resizable =不,copyhistory = yes,width = 400,height = 400);
}
< / java script >
< asp:CheckBox runat = server ID = chkGenerateSerialNumber AutoPostBack = true CausesValidation = < span class =code-keyword> false
OnCheckedChanged = chkGenerateSerialNumber_CheckedChanged / >
protected void chkGenerateSerialNumber_CheckedChanged( object sender,EventArgs e)
{
if (chkGenerateSerialNumber.Checked == true )
{
Session [ NoOfRows] = txtQty.Value;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append( @ < script language ='javascript'>) ;
sb.Append( @ open_win(););
sb.Append( @ < / script>);
ScriptManager.RegisterStartupScript( this , this .GetType(), javascript,sb.ToString(), true ); < span class =code-comment> // 它确实有效但在open_win()方法window.open(../ Stock / IPurchaseDetail.aspx, _blank,toolbar = yes,location = yes,directories = no,status = no,menubar = yes,scrollbars = yes,resizable = no,copyhistory = yes,width = 400,height = 400);没有接到电话
}
}
现在我有Session [NoOfRows] = txtQty.Value;但是另一个页面没有调用。
protected void Page_Load( object sender,EventArgs e)
{
if ( !IsPostBack)
{
NoOfRows Convert.ToInt32(( string )HttpContext.Current.Session [ NoOfRows]);
}
}
解决方案
你好,
至少有两种方法可以做到这一点。
- 类似于你的除了将所需参数作为查询字符串传递之外的代码。你的代码变成如下所示的代码。
function open_win(){
< span class =code-keyword> var s = document .getElementById( < span class =code-string> txtQty);
var url = ../ stock /IPurchaseDetail.aspx?txtQty = + encodeURIComponent(s.value);
window .open(url, _ blank , toolbar = yes,location = yes,directories = no,status = no,menubar = yes ,scrollbars = yes,resizable = no,copyhistory = yes,width = 400,height = 400);
}
- 此方法与上述非常相似,唯一的区别是您使用空白网址打开命名窗口并将现有表单POST到该窗口。以下代码段显示了如何完成此操作。
问候,
function open_win(){
< span class =code-keyword> var hWin = window .open( < span class =code-string>, hWinPurchase, toolbar = yes,location = yes,directories = no,status = no,menubar = yes,scrollbars = yes,resizable = no, copyhistory = yes,width = 400,height = 400);
var frm = document .getElementById(' YOUR_FORM_NAME');
frm.target = hWinPurchase;
frm.submit();
}
添加目标属性以形成标签,完成后。
现在每当点击按钮时,aspx将在新窗口中打开。
将以下代码粘贴到 .ASPX页面
< pre lang =HTML> < 表格 id = form1 < span class =code-attribute> runat = server target = _ blank >
<! - 在此处添加按钮 - >
< / form >
转到工具 - >选项 - >内容并取消选中阻止弹出窗口。
I want to know that how to open web page in different window and passed a value from javascript to c# on page load
<JavaScript>
function open_win()
{
var s=document.getElementById("txtQty");
window.open("../Stock/IPurchaseDetail.aspx","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</javascript>
<asp:CheckBox runat="server" ID="chkGenerateSerialNumber" AutoPostBack="true" CausesValidation="false"
OnCheckedChanged="chkGenerateSerialNumber_CheckedChanged" />
protected void chkGenerateSerialNumber_CheckedChanged(object sender, EventArgs e)
{
if (chkGenerateSerialNumber.Checked == true)
{
Session["NoOfRows"] = txtQty.Value;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append(@"open_win();");
sb.Append(@"</script>");
ScriptManager.RegisterStartupScript(this, this.GetType(), "javascript", sb.ToString(), true);// it does work but in open_win() method window.open("../Stock/IPurchaseDetail.aspx","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400"); does not get call
}
}
Now I have got Session["NoOfRows"] = txtQty.Value; but another page does not call.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
NoOfRows Convert.ToInt32((string)HttpContext.Current.Session["NoOfRows"]);
}
}
解决方案
Hello,
There are at-least two ways to do that.
- Similar to your code except that the desired parameters are passed as a Query String. S your code becomes something like one shown below.
function open_win() { var s = document.getElementById("txtQty"); var url = "../Stock/IPurchaseDetail.aspx?txtQty=" + encodeURIComponent(s.value); window.open(url, "_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400"); }- This method is very much similar to above, the only difference is that you open a named window with blank url and POST the existing form to that window. Following code snippet shows how this can be done.
Regards,
function open_win() { var hWin = window.open("", "hWinPurchase","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400"); var frm = document.getElementById('YOUR_FORM_NAME'); frm.target = "hWinPurchase"; frm.submit(); }
Add target attribute to form tag thats it, you are done.
Now whenever button is clicked, aspx will open in new window.
Paste the following code in your .ASPX page
<form id="form1" runat="server" target="_blank"> <!-- Add your buttons herere --> </form>
Go to Tools->Option->Content and uncheck block popup windows.
这篇关于如何在不同的窗口中打开.aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文