How to set the target frame for submitting a form in ASP.NET?

I have an asp.net page in an iframe where all links are targeted to _blank

<base target="_blank" /> 

But I want the form on it to be sent to _self (i.e. the iframe where the page is located) when one button is clicked. The form is a <asp:Panel> with a <asp:Button> control to submit it.

Where can I set a goal for this form? Since there is no <form> tag or <input> tag in the file (ASP.NET does them when it displays the page), I don’t know how to change the target to override the <base> .

+4
source share
2 answers

I just found this post on the asp.net mokeefe forums, which changes the target using javascript.

I just put it on my page and tried it. I had to make the following changes:

1. I use only asp tags, so I have <asp:Button> not <input type="button"> , and my onclick should be a server-side method I'm calling for a view. So I put this new javascript in OnClientClick :

 <asp:Button ID="cmdEmailSearch" runat="server" Text="Search" OnClick="cmdEmailSearch_Click" OnClientClick="javascript:pageSubmit()"/> 

2. I deleted myForm.submit () since ASP.NET renders the page by placing WebForm_DoPostBackWithOptions () javascript in the onclick button right after it places my Submit () page

 <script type="text/javascript"> function pageSubmit(){ // where form1 is the Parent Form Id var myForm = document.getElementById('form1'); myForm.target = '_self'; }// end function </script> 
+3
source

I'm not sure if you understood correctly, but you can set a goal in the form tag, for example:

 <form method=post action="Page.aspx" target="_self"> 
+4
source

Source: https://habr.com/ru/post/1301459/


All Articles