How to refer to a variable on another webform

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default How to refer to a variable on another webform

    How to refer to a variable on another webform

    Hi, I have a Webform1 with a public variable that is assigned a value before
    my Webform2 is displayed. In the Page_Load procedure of Webform2 I want to
    evaluate the value of the variable of Webform1.

    Code on Webform1

    Public MyVar1 As Integer

    Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.ServerClick

    MyVar1 = 1
    Server.Transfer("Webform2.aspx")

    End Sub


    Code on Webform2

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Dim Myvar2 As Integer
    Myvar2 = (Myvar1 from Webform1... Any Ideas?)

    End Sub

    T I Rislaa



    Tor Inge Rislaa Guest

  2. Similar Questions and Discussions

    1. How to refer Datagrid element
      :smile; I am using flex 2.0. How to refer a datagrid element directly in script dynamically without using the item edit event? For example I would...
    2. Refer to a button in a form by ID rather than name
      Hi, I would like to know if there is a way to call or refer to the radio button with it's id tag not the name because when I have the two...
    3. How to refer Page level variable from a control?
      Hi, I have a composite control inherited from System.Web.UI.Control. Inside of this control I need to refer to a Page level variable ...
    4. Blocking a refer
      Hi, Is there a way that I could block a certain refer from my website using PHP? Thanks, Wayne.
    5. Including WebForm Image Control in a Webform Table Control
      What is the code for including an image control in a Table control of a WebForm ???? regards
  3. #2

    Default Re: How to refer to a variable on another webform

    You can't. Once the webform1 finishes execution, it ceases to exist.

    You will have to store the value in session or pass it in the query string,
    or place it elsewhere where both forms can access to it.

    "Tor Inge Rislaa" <tor.inge.nospam@rislaa.no> wrote in message
    news:e5f32B1WDHA.2328@TK2MSFTNGP12.phx.gbl...
    > How to refer to a variable on another webform
    >
    > Hi, I have a Webform1 with a public variable that is assigned a value
    before
    > my Webform2 is displayed. In the Page_Load procedure of Webform2 I want to
    > evaluate the value of the variable of Webform1.
    >
    > Code on Webform1
    >
    > Public MyVar1 As Integer
    >
    > Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.ServerClick
    >
    > MyVar1 = 1
    > Server.Transfer("Webform2.aspx")
    >
    > End Sub
    >
    >
    > Code on Webform2
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > Dim Myvar2 As Integer
    > Myvar2 = (Myvar1 from Webform1... Any Ideas?)
    >
    > End Sub
    >
    > T I Rislaa
    >
    >
    >

    Marina Guest

  4. #3

    Default How to refer to a variable on another webform

    Open the Visual Studio.NET help....and type in the
    following in the address bar.....

    ms-
    help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskPassingValuesBetwe
    enWebFormsPages.htm

    It describes how to pass values in between web forms and
    of course you can always use query strings too.

    Thanks,

    Tap
    >-----Original Message-----
    >How to refer to a variable on another webform
    >
    >Hi, I have a Webform1 with a public variable that is
    assigned a value before
    >my Webform2 is displayed. In the Page_Load procedure of
    Webform2 I want to
    >evaluate the value of the variable of Webform1.
    >
    >Code on Webform1
    >
    >Public MyVar1 As Integer
    >
    >Private Sub Button1_ServerClick(ByVal sender As
    System.Object, ByVal e As
    >System.EventArgs) Handles Button1.ServerClick
    >
    > MyVar1 = 1
    > Server.Transfer("Webform2.aspx")
    >
    >End Sub
    >
    >
    >Code on Webform2
    >
    >Private Sub Page_Load(ByVal sender As System.Object,
    ByVal e As
    >System.EventArgs) Handles MyBase.Load
    >
    > Dim Myvar2 As Integer
    > Myvar2 = (Myvar1 from Webform1... Any Ideas?)
    >
    >End Sub
    >
    >T I Rislaa
    >
    >
    >
    >.
    >
    Tap Guest

  5. #4

    Default Re: How to refer to a variable on another webform

    That's not correct.

    You can use server.transfer as your code is beginning to. The next step is
    to recreate the first page on the second. You will need to do a CType on the
    context object that is passed using server.transfer.

    Dim Page1 As Page1 = CType(Context, Page1)

    The important thing is that if you can arrive at a page2 from more pages
    than page1 this code will error out if you try to make say, page3, into
    page1.

    I have some sample code in the code library on my website,
    [url]www.aboutfortunate.com[/url] for determining which page a context object came
    from. Just search for: "get page name".

    I hope this helps.

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
    news:eeivzL1WDHA.1512@TK2MSFTNGP11.phx.gbl...
    > You can't. Once the webform1 finishes execution, it ceases to exist.
    >
    > You will have to store the value in session or pass it in the query
    string,
    > or place it elsewhere where both forms can access to it.
    >
    > "Tor Inge Rislaa" <tor.inge.nospam@rislaa.no> wrote in message
    > news:e5f32B1WDHA.2328@TK2MSFTNGP12.phx.gbl...
    > > How to refer to a variable on another webform
    > >
    > > Hi, I have a Webform1 with a public variable that is assigned a value
    > before
    > > my Webform2 is displayed. In the Page_Load procedure of Webform2 I want
    to
    > > evaluate the value of the variable of Webform1.
    > >
    > > Code on Webform1
    > >
    > > Public MyVar1 As Integer
    > >
    > > Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e
    As
    > > System.EventArgs) Handles Button1.ServerClick
    > >
    > > MyVar1 = 1
    > > Server.Transfer("Webform2.aspx")
    > >
    > > End Sub
    > >
    > >
    > > Code on Webform2
    > >
    > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles MyBase.Load
    > >
    > > Dim Myvar2 As Integer
    > > Myvar2 = (Myvar1 from Webform1... Any Ideas?)
    > >
    > > End Sub
    > >
    > > T I Rislaa
    > >
    > >
    > >
    >
    >

    S. Justin Gengo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139