Click here to Skip to main content
14,303,095 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello

I have two pages names createbill.aspx and showbill.aspx. When User insert a data to createbill.aspx and click on submit button then data is stored in database and all the data is passed to showbill.aspx.

for this I am using the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class showbill : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {

            Label newlabel1 = new Label();
            Label newlabel2 = new Label();
            Label newlabel3 = new Label();
            Label newlabel4 = new Label();
            Label newlabel5 = new Label();
            Label newlabel6 = new Label();
            Label newlabel7 = new Label();
            Label newlabel8 = new Label();
            Label newlabel9 = new Label();
            Label newlabel10 = new Label();
            Label newlabel11 = new Label();
            Label newlabel12 = new Label();
            Label newlabel13 = new Label();
            Label newlabel14 = new Label();
          


          //  Label newlabel1, newlabel2, newlabel3, newlabel4, newlabel5, newlabel6, newlabel7, newlabel8, newlabel9, newlabel10, newlabel11, newlabel12, newlabel13, newlabel14;
                //Label newlabel15;
                //Label newlabel16;
                //Label newlabel17;
                //Label newlabel18;
                //Label newlabel19;
                //Label newlabel20;
                //Label newlabel21;
                //Label newlabel22;

            newlabel1 = (Label)PreviousPage.FindControl("Textbox6");
            newlabel2 = (Label)PreviousPage.FindControl("Textbox7");
            newlabel3 = (Label)PreviousPage.FindControl("Textbox8");
            newlabel4 = (Label)PreviousPage.FindControl("Textbox1");
            newlabel5 = (Label)PreviousPage.FindControl("Textbox2");
            newlabel6 = (Label)PreviousPage.FindControl("Textbox3");
            newlabel7 = (Label)PreviousPage.FindControl("Textbox4");
            newlabel8 = (Label)PreviousPage.FindControl("Textbox16");
            newlabel9 = (Label)PreviousPage.FindControl("Textbox17");
            newlabel10 = (Label)PreviousPage.FindControl("Textbox13");
            newlabel11 = (Label)PreviousPage.FindControl("Textbox18");
            newlabel12 = (Label)PreviousPage.FindControl("Textbox5");
            newlabel13 = (Label)PreviousPage.FindControl("Textbox14");
            newlabel14 = (Label)PreviousPage.FindControl("Textbox15");





            Label100.Text = newlabel1.Text;
            Label101.Text =  newlabel2.Text;
            Label102.Text =  newlabel3.Text;
            Label103.Text =  newlabel4.Text;
            Label104.Text =  newlabel5.Text;
            Label105.Text =  newlabel6.Text;
            Label106.Text =  newlabel7.Text;
            Label107.Text =  newlabel8.Text;
            Label108.Text =  newlabel9.Text;
            Label110.Text =  newlabel10.Text;
            Label111.Text =  newlabel11.Text;
            Label120.Text =  newlabel12.Text;
            Label121.Text =  newlabel13.Text;
            Label122.Text =  newlabel14.Text;

        }
        else
        {
            Response.Redirect("Default3.aspx");
        }
    }
}


THis code working fine for a single label but When i am using the multiple label I have got an error message "Null Instance"

So please Hellp..
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Why not do it the simple way? Store the data in the session, or a cookie, or pass it as a parameter to your Response.Redirect address? Personally, I'd go with the Session, so it never leaves the server. MSDN: How To Save Values in Session State[^]

You do seem to be trying to re-invent the wheel...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100