使用C#在新选项卡中打开页面 [英] Open page in new tab using C#
本文介绍了使用C#在新选项卡中打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。有人可以帮助我使用可以在按钮点击事件上打开新页面的代码。
然而,扭曲是在重定向到不同的页面和当前页面重新加载之前必须先执行一个函数。
这是我试过的:
页面名称:〜/ Application / BenefitsRequest.aspx < br $>
< asp :按钮 ID = btnSubmit runat = server 文字 = 提交和打印 宽度 = 150px OnClick = btnSubmit_Click OnClientClick = if(确认('你想提交并打印报销吗?')){this.style.background ='#98201a url(../ Images / HeaderFooterMainTemplate / loader.gif)'; this.value ='正在处理...';} else {return false;} / >
< span class =code-keyword> protected void btnSubmit_Click( object sender,EventArgs e )
{
string toDate = ;
string fromDate = ;
fromDate = 1/1/1900;
toDate = 1/1/1900;
try
{
Label lblLoggedAs =(Label)Master.FindControl( lblLoggedAs跨度>);
AddReimbursement( 3,drpReimburseType.SelectedValue.ToString()); // 这是一个功能
DeleteAllTrxRecord(); // 这是一个功能
string url = 〜/ Printing / ReimbursePrint.aspx?pg = 3;
Page.ClientScript.RegisterStartupScript( this .GetType(), openlink, window.open(url);, true );
Response.Redirect( 〜/ Application / BenefitsRequest.aspx);
}
catch (例外情况)
{
ClientScript.RegisterStartupScript( typeof (页面), 错误, < script type ='text / javascript'> alert(' + ex.Message + ')< / script>);
}
}
我的尝试:
i审了上面的代码,如果你有问题请评论
解决方案
试试这个
< pre lang =c#> string url = 〜 /Printing/ReimbursePrint.aspx?pg=3\" 跨度>;
Page.ClientScript.RegisterStartupScript( this .GetType(), openlink, window.open(' + url + '); window.location.href ='〜/ Application / BenefitsRequest.aspx',< span class =code-keyword> true );
Response.Redirect( 〜/ Application / BenefitsRequest.aspx);
使用您自己的表单ID为form1,在您说它不起作用之前检查pop阻止等等。
< asp:按钮 ID = btnSubmit runat = server 文字 = 提交和打印 宽度 = 150px OnClick = btnSubmit_Click OnClientClick = if(确认('你是吗?想提交并打印报销?')){document.getElementById('form1')。target ='_ blank'; window.setTimeout(函数(){的document.getElementById( 'form1中')目标= ''},1000); this.style.background ='#98201a url(../ Images / HeaderFooterMainTemplate / loader.gif)'; this.value ='正在处理...';} else {return false;} / >
Hi. Can someone help me with codes that can open a new page on button click event.
However, the twist is that a function has to be executed first before redirecting to a different page and the current page to reload.
Here is what I tried:
Page Name: ~/Application/BenefitsRequest.aspx
<asp:Button ID="btnSubmit" runat="server" Text="Submit & Print" Width="150px" OnClick="btnSubmit_Click" OnClientClick="if(confirm('Do you want to submit and print the reimbursement?')){this.style.background='#98201a url(../Images/HeaderFooterMainTemplate/loader.gif)'; this.value = 'Processing...';}else{return false;}" />
protected void btnSubmit_Click(object sender, EventArgs e)
{
string toDate="";
string fromDate="";
fromDate = "1/1/1900";
toDate = "1/1/1900";
try
{
Label lblLoggedAs = (Label)Master.FindControl("lblLoggedAs");
AddReimbursement("3", drpReimburseType.SelectedValue.ToString());//THIS IS A FUNCTION
DeleteAllTrxRecord(); //THIS IS A FUNCTION
string url = "~/Printing/ReimbursePrint.aspx?pg=3";
Page.ClientScript.RegisterStartupScript(this.GetType(), "openlink", "window.open(url);", true);
Response.Redirect("~/Application/BenefitsRequest.aspx");
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(typeof(Page), "Error", "<script type='text/javascript'>alert('"+ex.Message+"')</script>");
}
}
What I have tried:
i TRIED THE ABOVE CODE, please comment if u have questions
解决方案
try this
string url = "~/Printing/ReimbursePrint.aspx?pg=3"; Page.ClientScript.RegisterStartupScript(this.GetType(), "openlink", "window.open('" + url + "'); window.location.href = '~/Application/BenefitsRequest.aspx'", true);Response.Redirect("~/Application/BenefitsRequest.aspx");
Use your own form id for "form1", and before you say it "doesn't work" check for pop-up blockers etc.
<asp:Button ID="btnSubmit" runat="server" Text="Submit & Print" Width="150px" OnClick="btnSubmit_Click" OnClientClick="if(confirm('Do you want to submit and print the reimbursement?')){document.getElementById('form1').target='_blank'; window.setTimeout(function(){document.getElementById('form1').target=''},1000); this.style.background='#98201a url(../Images/HeaderFooterMainTemplate/loader.gif)'; this.value = 'Processing...';}else{return false;}" />
这篇关于使用C#在新选项卡中打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文