Solved

Passing variable from webform to webform

Posted on 2004-09-20
5
298 Views
Last Modified: 2010-08-05
Trying to populate a ddl from a variable that got its value on a previous page

page one:     gmstrVendorRemitId = UCase(Trim(txtRemitID.Text))

page two:      ddlRemit.SelectedItem.Text = gmstrVendorRemitId

I get this error: Object reference not set to an instance of an object for page two.

Any ideas?

thanks,

6784

0
Comment
Question by:6784
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
KGreg earned 200 total points
ID: 12104540
page one:

        Session.Add("VendorRemitId", UCase(Trim(txtRemitID.Text)))


page two:

        if not isnothing(session.Item("VendorRemitID") then

                ddlRemit.SelectedItem.Text = Session.Item("VendorRemitID")

        End If


KGreg
0
 

Author Comment

by:6784
ID: 12104847
I get the same error

this is my first ASP or ASP.NET application. I know nothing about Session. With the input of your code, thats the only place I use Session. From what I have seen in othe apps, I know this is wrong. Just don't understand the whole Session concept. Think I should stop coding and start reading.
0
 
LVL 2

Expert Comment

by:Mehrdad_Y
ID: 12104854
Hello
You have 3 ways to transfer data from one form to the other one:
1- Quary Strings: When you want to redirect user from one page to the other, use:
     Response.Redirect("http://PageTwo.aspx?VARIABLE1=VALUE1&VARIABLE2=VALUE2...")

    Then use the following code to get the value from the Quary String:
    Variable1=Me.Request.QuaryString("VARIABLE1")
    Variable2=Me.Request.QuaryString("VARIABLE2")
    ...
2- Cookies: Store data on the client machine:
    In page 1 write: Me.Response.Cookies.Add("VARIABLE1","VALUE1")
    In page 2 write: Variable1=Me.Request.Cookies("VARIABLE1").Value

3- Use Session or Application State:
    In Page 1 write: Session("Variable1")=Value1
    In Page 2 write: Variable2=Session("Variable2")

    Or use Application instead of Session.

Notes:
- In the third solution, anything stored in the session, will be only available for the current user, but if you store data in the Application, it will be available to all the users.
- The first solution has the best performance, but it sends data in clear text, and data is viewable from the addressbar.
- The second one, has a limit of capacity in the cookies (64K) and is not secure too, as the data is stored in the user's machine.
- The third one, is secure, as data is stored in the server, but has an effect of performance in heavy traffice environments.
0
 
LVL 6

Expert Comment

by:KGreg
ID: 12105610
this code is on page one:

        Session.Add("VendorRemitId", UCase(Trim(txtRemitID.Text)))


page two - AFTER THE PAGE IS LOADED.. you can't explicitly set the value of a control on a webform unless the page is loaded.. so this code has to be written in the codepage for page 2.. in the LOAD EVENT:

        if not isnothing(session.Item("VendorRemitID") then

                ddlRemit.SelectedItem.Text = Session.Item("VendorRemitID")

        End If

NOTE:  Session variables are probably more practical, because you don't want to let users control the flow of your application by encoding url's or cookies.


KGREG

0
 

Author Comment

by:6784
ID: 12106142
works now because I had the code wrong for populating the ddl.

thanks for the info Mehrdad_Y  
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net Tranfer data between to VB.Net apps 8 40
Winform Module - What is the ASP.Net equiv 2 28
Open a link in vb.net 2 16
Visual studio 2015 1 21
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question