Dave
Dave

Reputation: 159

Cross-Page Posting a GridView

I have a problem with Cross-Page Posting a GridView.

The error I'm getting is the following: Object reference not set to an instance of an object.

Steps I took:

  1. Create the new Page and add a GridView
  2. Create a button with PostBack to the new page.

    <asp:Button ID="Button1" Text="Button 1" PostBackUrl="~/Page2.aspx?button=1" runat="server" />
    
  3. Adding code behind to the new Page.

    protected void Page_Load(object sender, EventArgs e)
    {
       if (Page.PreviousPage == null)
       {
          Label1.Text = "Vul een planing in.";
       }
       else
       {
          ContentPlaceHolder pageContent =
              (ContentPlaceHolder)(Page.PreviousPage.FindControl("Content1"));
          GridView1.DataSource = pageContent.FindControl("GridView2"); // In this line I'm getting the error
       }
    }
    

Looking at the error I forgot a reference. Thnx for the help:)

Upvotes: 1

Views: 667

Answers (2)

SpruceMoose
SpruceMoose

Reputation: 10320

Looks like the Server.Transfer is the answer to your problem. See this post: Page.PreviousPage.FindControl is NULL

Upvotes: 4

RVD
RVD

Reputation: 66

Please check followinf link to fetch previous page control value in another page, so you can use same login in your code, but if the griview contains large amount of data your page performance will get reduced.

http://www.allinterview.com/showanswers/36626/page4.html

Upvotes: 1

Related Questions