views:

261

answers:

2

I have an asp.net page in an iframe where all links target _blank

<base target="_blank" />

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

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.

A: 

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. 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. 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>
adambox
+1  A: 

I'm not sure if I understood you right, but you can set the target in the form tag, like this:

<form method=post action="Page.aspx" target="_self">
VinTem
the trick is I'm using the ASP.NET one-form-per-page thing. My "form" is an asp:Panel tag, so I can't put the target attribute anywhere (I need my <base target="_blank"> so my links on the page go to a new tab)
adambox