如何设置在ASP.NET表单提交的目标框架? [英] How do I set the target frame for form submission in ASP.NET?
问题描述
我在iframe一个asp.net页面,所有链接的目标_blank
I have an asp.net page in an iframe where all links target _blank
<base target="_blank" />
但我想它的形式提交给_self(即所在的页面所在的iframe)单击一个按钮时。形式是一个&LT; ASP:面板&gt;
与&LT; ASP:按钮&gt;作为在提交
控制
我在哪里可以设置目标这种形式?由于没有一个&LT;形式&GT;
标记或&LT;输入&GT;
文件(ASP的标签。 NET使他们当它呈现的页面),我不知道如何改变来覆盖我的&LT;基地方式&gt;
标签
Where can I set the target for this form? Since there isn't a <form>
tag or an <input>
tag in the file (ASP.NET makes them when it renders the page), I don't know how to change the target to override my <base>
tag.
推荐答案
我刚刚发现这帖子由asp.net论坛 mokeefe 是由JavaScript改变目标
I just found this post on the asp.net forums by mokeefe that changes the target by javascript.
我只是把它在我的网页,并尝试过。我不得不做出这些修改
I just put it in my page and tried it. I had to make these modifications:
1 我只使用ASP标记,所以我有&LT; ASP:按钮&GT;
不是&LT ;输入类型=按钮&GT;
我的的onclick 必须是服务器端的方法,我号召提交。因此,我把这个新的JavaScript中的的OnClientClick
1. I'm using asp tags only, so I have <asp:Button>
not <input type="button">
and my onclick has to be the server-side method I'm calling on submission. Therefore I put this new javascript in OnClientClick:
<asp:Button ID="cmdEmailSearch" runat="server" Text="Search"
OnClick="cmdEmailSearch_Click"
OnClientClick="javascript:pageSubmit()"/>
2 我删除了myForm.submit(),因为ASP.NET呈现页面将在 WebForm_DoPostBackWithOptions()按钮的的onclick 它把右后我的 pageSubmit()
2. I removed the myForm.submit() since ASP.NET renders the page putting the WebForm_DoPostBackWithOptions() javascript in the button's onclick right after it puts my pageSubmit()
<script type="text/javascript">
function pageSubmit(){
// where form1 is the Parent Form Id
var myForm = document.getElementById('form1');
myForm.target = '_self';
}// end function
</script>
这篇关于如何设置在ASP.NET表单提交的目标框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!