473,237 Members | 1,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

How to post the data to a new window and control the new window's property?

When we submit the form data to another page, we usually do the following:

<form action="display.aspx" method="post"> will submit the form data and
open
display.asp in the current browser

<form action="display.aspx" method="post" target="_blank"> will submit the
form data
and open display.asp in a new browser
Now, what I want is to open display.asp in a new browser, but control the
window's size,
and disable the status bar, title bar, and address bar of a new browser.

If I do this, it can only open a html page, but not post the data to
display.asp.

window.open('display.aspx', "newWin",
"scrollbars=0,menubar=0,toolbar=0,location=0,statu s=0");

any ideas? thanks!!



Nov 18 '05 #1
2 12501
You can post with JS: read my paper on this comment which i had posted in
past.

Introduction
One of the biggest changes from ASP to ASP.NET is the postback process. By
design, ASP.NET pages post form data back to themselves for processing. For
most situations, this is an acceptable process. But if a page must post form
data to another site or another ASP.NET page, this is impractical. The
current ASP.NET postback process supports lots of ways to manage this
process.

Use Server.Transfer() to send posted fields to another page. This has the
unfortunate side effect of not changing the user's URL.
Pass the items on a querystring, bundling them manually and using
Response.Redirect() to send the new querystring to another page. The
querystring has both security and length issues.
Pass the items on a post. Create a custom function to read the current items
and send them via an HTTP post.
Use an HTML form instead of a web form. Remove the runat="server" attribute
from the Form tag. Unfortunately, the validator controls can no longer be
used, and that is the main reason I decided to use a JavaScript solution.
Use a simple JavaScript function to alter the page behavior on the client.
I am going to describe a technique using a simple client-side JavaScript.
The advantage of this is that it is quick and simple, especially for
developers just starting out with ASP.NET or for simple applications.
Additionally, when migrating ASP applications to ASP.NET, this little
technique can help reduce migration time by allowing you to keep, the ASP
page-to-page posting behavior. The one downside is that users can choose to
operate their browser without JavaScript, thus negating this technique. If
this is a serious concern for you, look into the third option listed above.

Background
There are two problems to overcome when using JavaScript to change the
posting behavior of ASP.NET. The first problem is the self-postback.
JavaScript allows the action attribute of the HTML Form tag to be changed on
the client. It is the content of the post that causes ASP.NET to have the
most serious problems. When an ASP.NET page receives a post, it checks for a
field called __VIEWSTATE (that's 2 underscore symbols) in the post. ASP.NET
is using this field for many reasons, most outside the scope of this
article. But, one thing the __VIEWSTATE field does contain is internal
validation for ASP.NET. If you simply post the __VIEWSTATE field to a
different ASP.NET page, than the page that filled the __VIEWSTATE field,
ASP.NET will throw an exception:

"The viewstate is invalid for this page and might be corrupted."
If we attempt to remove the data from the __VIEWSTATE field prior to a post
with JavaScript, the same exception is thrown.

So, in order to post to another ASP.NET page, the __VIEWSTATE field cannot
be passed to the next ASP.NET page. JavaScript allows us to rename the
__VIEWSTATE field and change the action attribute of the form tag.

Using the code
In the HTML portion of our ASP.NET page, we need to include the JavaScript
function, NoPostBack. It could reside in a separate file, but is included
here in the page for simplicity.

<script language="javascript">
function noPostBack(sNewFormAction)
{
document.forms[0].action = sNewFormAction;
document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}
</script>
The first line sets the form's action attribute to a new location that is
passed to the function. The second line renames the __VIEWSTATE field. It
can be called anything other than it's original name or the name of your
other form items. If you are trying to save bandwidth, you could also set
the value of the __VIEWSTATE field to "". In the ASP.NET Page_Load function,
only one line of code is necessary:

private void Page_Load(object sender, System.EventArgs e)
{
Submit.Attributes.Add("onclick", "noPostBack('secondform.aspx');");
}
This adds an onclick attribute to the Submit button, and in this attribute
we are specifying the new page or location for the post. When the button is
clicked, it calls the JavaScript function before the form post occurs,
changing the default location from the page itself to somewhere else.

If the data is posted to another ASP.NET form, simply handle the form items
using Request.Form syntax:

private void Page_Load(object sender, System.EventArgs e)
{
Result.Text = Request.Form["SomeText"].ToString();
}
Points of interest
When dealing with Netscape 4 and a CSS-based layout, the JavaScript needs to
adapt slightly. Each <div> is considered a layer, so you must address the
layer specifically in the JavaScript. Assume the form is contained inside of
a <div> named Content:

<div id="Content" name="Content">
<form method="post" id="Form1" runat="server">

</form>
</div>
The JavaScript now needs to differentiate between Netscape 4 and the other
DOM aware browsers. Check for document.layers to identify Netscape 4, and
simply use the syntax appropriate for that browser:

<script language="javascript">
<!--
function noPostBack(sNewFormAction)
{
if(document.layers) //The browser is Netscape 4
{
document.layers['Content'].document.forms[0].__VIEWSTATE.name =
'NOVIEWSTATE';
document.layers['Content'].document.forms[0].action =
sNewFormAction;
}
else //It is some other browser that understands the DOM
{
document.forms[0].action = sNewFormAction;
document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}
}
-->
</script>
"Matt" <ma*******@hotmail.com> wrote in message
news:ed*************@TK2MSFTNGP10.phx.gbl...
When we submit the form data to another page, we usually do the following:

<form action="display.aspx" method="post"> will submit the form data and
open
display.asp in the current browser

<form action="display.aspx" method="post" target="_blank"> will submit the
form data
and open display.asp in a new browser
Now, what I want is to open display.asp in a new browser, but control the
window's size,
and disable the status bar, title bar, and address bar of a new browser.

If I do this, it can only open a html page, but not post the data to
display.asp.

window.open('display.aspx', "newWin",
"scrollbars=0,menubar=0,toolbar=0,location=0,statu s=0");

any ideas? thanks!!


Nov 18 '05 #2
window.open, doesn't support a form post, you must use a get (url encode the
values).

but after users install xp service pack 2, window.open is no longer allowed
to suppress the status bar, or title, (kiosk mode is different also).

-- bruce (sqlwork.com)

"Matt" <ma*******@hotmail.com> wrote in message
news:ed*************@TK2MSFTNGP10.phx.gbl...
When we submit the form data to another page, we usually do the following:

<form action="display.aspx" method="post"> will submit the form data and
open
display.asp in the current browser

<form action="display.aspx" method="post" target="_blank"> will submit the
form data
and open display.asp in a new browser
Now, what I want is to open display.asp in a new browser, but control the
window's size,
and disable the status bar, title bar, and address bar of a new browser.

If I do this, it can only open a html page, but not post the data to
display.asp.

window.open('display.aspx', "newWin",
"scrollbars=0,menubar=0,toolbar=0,location=0,statu s=0");

any ideas? thanks!!


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
3
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.asp" method="post"> will submit the form data and open display.asp in the current browser <form...
2
by: Rob Richardson | last post by:
Greetings! I just developed a little control I've wanted for ages. It links a textbox and a label into a single control. At first, I gave it a property named LabelText and another named...
2
by: KathyB | last post by:
Hi, In the pageload of my aspx file I have the following (in both not in postback and is postback)... btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial Numbers',...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
1
by: Bob Altman | last post by:
How do I bind a value from My.Settings to a property on a control on a Windows form? I've created a setting called My.Settings.Value1 of type String. Now I want to create a "Settings" dialog...
7
by: Jason | last post by:
Hello I've got a very simple C# app, that has a datagrid, a text box, and a button which when clicked opens a second form... Form2 frm2 = new Form2(); frm2.Show(); When I place a datagrid,...
4
by: Bosconian | last post by:
I have created a form tool page that consists of several dropdowns which allows a user to drill down and select a desired document for viewing in an external window. I need to post the form data to...
9
by: =?Utf-8?B?VGVycnk=?= | last post by:
Think it is great the way that you can set up a datsource, value member, and display member for a combobox, and map a 'code' to a 'description' and back again by binding the combobox to a...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.