Solved

Passing variable from webform to webform

Posted on 2004-09-20
5
264 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now