Link to home
Start Free TrialLog in
Avatar of RedPhoenix3
RedPhoenix3Flag for United States of America

asked on

Retrieving values using PreviousPage

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

ASKER CERTIFIED SOLUTION
Avatar of Ajay Sharma
Ajay Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RedPhoenix3

ASKER

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!