ASP.NET - Data transfer between two pages
<p>I need to transfer data from controls on page2 to GridView control on page1 upon pressing  button. (without using database)</p>

<p>I tried using DataTable for storing data and arrange them into columns/rows.</p>

<p>But when I click on button I get an exception saying: "Object reference not set to an instance of an object." in line 58. --> DataRow dr = dt.NewRow();</p>

<p><strong>Page2 c# code:</strong></p>

<pre><code>public partial class WebForm1 : System.Web.UI.Page
{
    //Lastnosti
    public string IDizposoje
    {
        get { return TextBox3.Text; }
    }

    public string Ime
    {
        get { return TextBox1.Text; }
    }

    public string Priimek
    {
        get { return TextBox2.Text; }
    }

    public string DatumIzposoje
    {
        get { return Calendar1.SelectedDate.ToString(); }
    }

    public string DatumVrnitve
    {
        get { return Calendar2.SelectedDate.ToString(); }
    }

    public string VrstaAvtomobila
    {
        get { return ListBox1.SelectedItem.Text; }
    }

    //Koda, ki se izvrši ob zagonu
    protected void Page_Load(object sender, EventArgs e, DataTable dt)
    {         
    }

    //Ob kliku na gumb "Prekliči" zapremo stran
    protected void Button2_Click(object sender, EventArgs e)
    {
        //Response.Redirect("~/Default.aspx");
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
    }

    //Napolnimo tabelo s podatki
    public void NapolniTabelo(DataTable dt)
    {
        DataRow dr = dt.NewRow();

        dr["ID"] = TextBox3.Text;
        dr["Ime"] = TextBox1.Text;
        dr["Priimek"] = TextBox2.Text;
        dr["Datum izposoje"] = Calendar1.SelectedDate.ToString();
        dr["Datum vrnitve"] = Calendar2.SelectedDate.ToString();
        dr["Vrsta avtomobila"] = ListBox1.SelectedValue.ToString();

        dt.Rows.Add(dr);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        NapolniTabelo((DataTable)Session["tabela"]);
        /*Session["ID"] = TextBox3.Text;
        Session["Ime"] = TextBox1.Text;
        Session["Priimek"] = TextBox2.Text;
        Session["Datum izposoje"] = Calendar1.SelectedDate.ToString();
        Session["Datum vrnitve"] = Calendar2.SelectedDate.ToString();
        Session["Vrsta avtomobila"] = ListBox1.SelectedValue.ToString();*/
        Response.Redirect("Default.aspx");
    }

    //Ponastavimo gradnike
    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        Calendar1.SelectedDate = DateTime.Now;
        Calendar2.SelectedDate = DateTime.Now;
        ListBox1.SelectedIndex = 0;
    }
}
</code></pre>

<p><strong>Page1 c# code:</strong></p>

<pre><code>public partial class _Default : System.Web.UI.Page
{
    private DataTable UstvariTabelo()
    {
        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("ID", typeof(string)));
        dt.Columns.Add(new DataColumn("Ime", typeof(string)));
        dt.Columns.Add(new DataColumn("Priimek", typeof(string)));
        dt.Columns.Add(new DataColumn("Datum izposoje", typeof(string)));
        dt.Columns.Add(new DataColumn("Datum vrnitve", typeof(string)));
        dt.Columns.Add(new DataColumn("Vrsta vozila", typeof(string)));

        return dt;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        WebForm1 druga = new WebForm1();
        DataTable tabela = UstvariTabelo();

        druga.NapolniTabelo(tabela);

        this.GridView1.Visible = true;
        this.GridView1.DataSource = ((DataTable)Session["tabela"]);
        this.GridView1.DataBind();
    }
}
</code></pre>

<p>Where did I go wrong?</p>
