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

Discussion in 'ASP .Net' started by Paul Hale, Oct 28, 2003.

  1. Paul Hale

    Paul Hale Guest

    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.
     
    Paul Hale, Oct 28, 2003
    #1
    1. Advertising

  2. Paul Hale

    Stephan Bour Guest

    Re: Is it possible to read a textbox control from another webform?

    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 , Paul Hale at
    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.
     
    Stephan Bour, Oct 28, 2003
    #2
    1. Advertising

  3. > 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" <> wrote in message
    news:...
    > 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.
     
    Kevin Spencer, Oct 28, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    537
    S. Justin Gengo
    Jul 16, 2003
  2. tom
    Replies:
    4
    Views:
    9,869
    S. Justin Gengo
    Nov 13, 2003
  3. et
    Replies:
    1
    Views:
    525
    Yunus Emre ALPĂ–ZEN [MCSD.NET]
    Jun 29, 2005
  4. et
    Replies:
    0
    Views:
    146
  5. Rob R. Ainscough
    Replies:
    3
    Views:
    332
    Rob R. Ainscough
    Jun 14, 2005
Loading...

Share This Page