By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

Is it possible to read a textbox control from another web form?

P: n/a
Hi,

I have two web forms (lets call them webform1 and webform2) that run
as part of the same web application.

Webform1 contains a text box. I would like to pop up a new browser
window (containing webform2) and read the contents of the text box in
webform1 and display in webform2.

Is it possible to do this without posting the contents in a form or
over http or setting up a cache.

Ie - Something like declaring the text box public in webform1 and
then...

(Code in webform 2)

dim objWebForm1 as webform1)
response.write(objWebForm1.mytextbox.text)

Hopefully you get what im trying to do!

Thanks for any help!

Paul.
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
One ugly way to do it is to use Response.Redirect and embed the textbox.Text
string into the URL for the webform 2.

A more elegant way is to use Session State. Here is an example that assumes
the ID of your text box is TextBox (code behind in C#).

if (Session["Form1"] == null) {
Form1 = new FormEntry();
Session["Form1"] = Form1;
}
else {
Form1 = (FormEntry) Session["Form1"];
}

public class FormEntry {
private String mTextBox = "";

public String TextBox {
get {
return mTextBox;
}
set {
mTextBox = value
}
}

Then insert in your form2 HTML:
<%= Form1.TextBox %>

in article 2d**************************@posting.google.com, Paul Hale at
pa*******@safenames.co.uk wrote on 10/28/03 12:41:
Hi,

I have two web forms (lets call them webform1 and webform2) that run
as part of the same web application.

Webform1 contains a text box. I would like to pop up a new browser
window (containing webform2) and read the contents of the text box in
webform1 and display in webform2.

Is it possible to do this without posting the contents in a form or
over http or setting up a cache.

Ie - Something like declaring the text box public in webform1 and
then...

(Code in webform 2)

dim objWebForm1 as webform1)
response.write(objWebForm1.mytextbox.text)

Hopefully you get what im trying to do!

Thanks for any help!

Paul.


Nov 17 '05 #2

P: n/a
> Is it possible to do this without posting the contents in a form or
over http or setting up a cache.
It is possible. It requires a number of things to be true. when a JavaScript
in an HTML document uses the window.open() method to open a new browser
instance, the function returns a handle to the window opened. This enables
the HTML documents in both windows to "talk to" each other. In the child
window, the parent window is accessible as "opener." In the parent window,
the child window is accessible as the handle created when opening the
window.

So, for example, if the first window has a textbox in it with the name "foo"
the child window can grab it's value thusly:

var s = opener.forms[0].foo.value;

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Paul Hale" <pa*******@safenames.co.uk> wrote in message
news:2d**************************@posting.google.c om... Hi,

I have two web forms (lets call them webform1 and webform2) that run
as part of the same web application.

Webform1 contains a text box. I would like to pop up a new browser
window (containing webform2) and read the contents of the text box in
webform1 and display in webform2.

Is it possible to do this without posting the contents in a form or
over http or setting up a cache.

Ie - Something like declaring the text box public in webform1 and
then...

(Code in webform 2)

dim objWebForm1 as webform1)
response.write(objWebForm1.mytextbox.text)

Hopefully you get what im trying to do!

Thanks for any help!

Paul.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.