Submitting a form to a new window in ASP.NET

G

Guest

I have a form that I want to submit to a different page and in a new window.

I have done this using an HTML button and putting a target="_blank"
attribute in the FORM tag. This does give me the results, but I'm unable to
control the size and other properties of this new window.

If I try to takeout the runat=server attribute from the form element and
write a custom javascript function, then my other web controls in the form
(dropdown lists and others) start giving me errors.

What will be a neat and clean solution to do this... Any help?

Thanks in advance.
 
G

gaidar

There is no possiblility in ASP.NET 1.x to submit a form to another page
without playing some tricks (you should create your own page class that
inherit Page class). But you can do it fully on client side.
Add an HTML button:

<input type="button" name="submit" value="Submit a Form" onclick="return
submitNew()">

Suppose you have two textboxes on your form, named Text1 and Text2, then
your rendered to HTML form should look like:
<form id="frmMain">
Text1: <input type="text" id="Text1"><br />
Text2: <input type="text" id="Text2"><br />
<input type="button" name="submit" value="Submit a Form" onclick="return
submitNew()">
</form>

And add a simple JavaScript to your page:
<script>
function submitNew() {
window.open("http://somehost.com/SomePage.aspx?Text1=" +
frmMain.Text1.Value + "&Text2=" + frmMain.Text2.Value, "New Window",
"scrollbars=0, height=400, width=600, left=20, top=20");
}
</script>

Gaidar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top