Hello, I am trying to post data from one page to another, I keep getting an error message every time I run the code "Object reference not set to an instance of an object.". Please help

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If PreviousPage.IsCrossPagePostBack Then
            CURRENT_POLICY.Text = "PO_NUMBER:" + CType(PreviousPage.Master.FindControl("PO_NUMBER"), TextBox).Text
        Else
        End If
    End Sub

the control that I am trying to get the value from is PO_NUMBER on the first page. I am using Visual Studio 2008. Thank you

P.S. All of the pages use the master page

Hi there
in master page

<asp:TextBox ID="TextBox1" runat="server" Text="hello"></asp:TextBox>

Try this code in referral page. this should work with you

txtProductName.Text = CType(Page.Master.FindControl("textbox1"), TextBox).Text

Pls. Mark as solved if it helps you!!!

Thank you for the reply, but I am not quite following you, are you saying put the textbox in the master page? My pages referance the master page for the layout and links, but the content is what I am working in. Example I have two pages test1.aspx and test2.aspx, both of the pages reference the master page for layout and links. what I am trying to do is cross post from test1.aspx to test2.aspx. Not from master to test1.aspx. As it stands I can crosspost from test1.aspx to test2.aspx without using the master page. please help

Hi there
in master page

<asp:TextBox ID="TextBox1" runat="server" Text="hello"></asp:TextBox>

Try this code in referral page. this should work with you

txtProductName.Text = CType(Page.Master.FindControl("textbox1"), TextBox).Text

Pls. Mark as solved if it helps you!!!

Hello, I am trying to post data from one page to another, I keep getting an error message every time I run the code "Object reference not set to an instance of an object.". Please help

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If PreviousPage.IsCrossPagePostBack Then
            CURRENT_POLICY.Text = "PO_NUMBER:" + CType(PreviousPage.Master.FindControl("PO_NUMBER"), TextBox).Text
        Else
        End If
    End Sub

the control that I am trying to get the value from is PO_NUMBER on the first page. I am using Visual Studio 2008. Thank you

P.S. All of the pages use the master page

The problem is when u find ur master page in the current page your current page is not able to find the master page
i.e,

PreviousPage.Master.FindControl("PO_NUMBER")

would be returning null

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.