Solved

Retrieving values using PreviousPage

Posted on 2008-10-02
2
449 Views
Last Modified: 2008-10-24
I am new to asp.Net.  I am attempting to retrieve values from fields on a previous page assign their values to fields on the new page and insert those values into a table.  

When the page loads the previous page values do appear in the correct fields but I keep getting the following error: "Object reference not set to an instance of an object. " 

The line of code identified is: Line 133:    Dim myPage As ContentPlaceHolder = PreviousPage.Master.FindControl("ContentPlaceHolder1")

Here is my code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 

        Dim body As HtmlGenericControl = Master.FindControl("MasterBody")

        body.Attributes.Add("onkeydown", "HandleRefresh(event,'" & Request.RawUrl & "');")

        Dim myPage As ContentPlaceHolder = PreviousPage.Master.FindControl("ContentPlaceHolder1")
 

        Dim EmpName As DropDownList = myPage.FindControl("EmpNameCom")

        EN = EmpName.SelectedValue

        Dim RevName As DropDownList = myPage.FindControl("RevNameCom")

        Rev = RevName.SelectedValue

        Dim EmpPos As DropDownList = myPage.FindControl("EmpPosCom")

        Pos = EmpPos.SelectedValue

        Dim State As DropDownList = myPage.FindControl("StateCom")

        St = State.SelectedValue

        Dim SurveyType As DropDownList = myPage.FindControl("SurveyTypeCom")

        SurT = SurveyType.SelectedValue
 

    End Sub
 

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

        'sets the FormView in the correct mode depending on the action

        Dim myPage As ContentPlaceHolder = Page.Master.FindControl("ContentPlaceholder1")

        Dim fv As FormView = myPage.FindControl("FormView1")

        If Request.QueryString("mode") = "3" Then

            Me.FormView1.ChangeMode(FormViewMode.Edit)

            'If IsPostBack Then

            '    getClaimRepData()

            'End If

        ElseIf Request.QueryString("mode") = "1" Then

            Me.FormView1.ChangeMode(FormViewMode.ReadOnly)

        Else

            Me.FormView1.ChangeMode(FormViewMode.Insert)

            Dim txt As TextBox = fv.FindControl("SurveyDate")

            txt.Text = FormatDateTime(Now(), DateFormat.ShortDate)

            Dim txt1 As TextBox = fv.FindControl("EmpName")

            txt1.Text = EN

            Dim txt2 As TextBox = fv.FindControl("RevName")

            txt2.Text = Rev

            Dim txt3 As TextBox = fv.FindControl("EmpPos")

            txt3.Text = Pos

            Dim txt4 As DropDownList = fv.FindControl("State")

            txt4.SelectedValue = St

            Dim txt5 As TextBox = fv.FindControl("SurveyType")

            txt5.Text = SurT

        End If
 

    End Sub

Open in new window

0
Comment
Question by:RedPhoenix3
2 Comments
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 500 total points
ID: 22632427
instead of using controls use the property to get data.

read this

http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx

http://steveorr.net/faq/PassValues.aspx
0
 

Author Comment

by:RedPhoenix3
ID: 22654301
Thank you for this suggestion.  I omitted mentioning that I am working on a corporate system where we do not currently have use of Session State in .NET.  While I can see where this solution would work with the use of session state, I need another work around.  Any suggestions?

Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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