0

I am creating a form from code behind and in my aspx I place a placeholder to create a design but I am not able to retrieve any input values even if I enter an input into the textboxes.

The user data should insert the entered values into the database. I was prompted as null even when I added a default value into the field.

Only the UI appeared but none of the fields are able to retrieve a value from user's input.

protected void Page_Load(object sender, EventArgs e)
    {

        //Get the values from TourPackageDetails.aspx
        int rPackageId = Convert.ToInt16(Request.QueryString["packageId"]);
        int tbCapacity = Convert.ToInt16(Request.QueryString["tbCapacity"]);

        phTravellerForm.Controls.Add(new LiteralControl("<h3>"));
        Label lblTraveller = new Label();
        lblTraveller.Text = "Traveller ";
        phTravellerForm.Controls.Add(lblTraveller);
        phTravellerForm.Controls.Add(new LiteralControl("</h3>"));

        /** Start of  Traveller's name **/
        Label lblName = new Label();
        lblName.Text = "Name: ";
        phTravellerForm.Controls.Add(lblName);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));

        TextBox tbName = new TextBox();
        tbName.Text = "";
        phTravellerForm.Controls.Add(tbName);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));
        /** End of  Traveller's name **/

        /** Start of  Traveller's Contact **/
        Label lblContact = new Label();
        lblContact.Text = "Contact No: ";
        phTravellerForm.Controls.Add(lblContact);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));

        TextBox tbContact = new TextBox();
        tbContact.Text = "";
        phTravellerForm.Controls.Add(tbContact);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));
        /** End of  Traveller's Contact **/

        /** Start of  Traveller's nationality **/
        Label lblNationality = new Label();
        lblNationality.Text = "Nationality: ";
        phTravellerForm.Controls.Add(lblNationality);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));

        TextBox tbNationality = new TextBox();
        tbNationality.Text = "";
        phTravellerForm.Controls.Add(tbNationality);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));
        /** End of  Traveller's nationality **/

        /** Start of passport number **/
        Label lblPassport = new Label();
        lblPassport.Text = "Passport Number: ";
        phTravellerForm.Controls.Add(lblPassport);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));

        TextBox tbPassport = new TextBox();
        tbPassport.Text = "";
        phTravellerForm.Controls.Add(tbPassport);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));
        /** End of passport number **/

        /** Start of passport expiry date **/
        Label lblPassportExpiry = new Label();
        lblPassportExpiry.Text = "Passport Expiry Date: ";
        phTravellerForm.Controls.Add(lblPassportExpiry);

        phTravellerForm.Controls.Add(new LiteralControl("<br />"));

        //Passport expiry date

        TextBox tbDOB = new TextBox();
        tbDOB.Text = "DD/MM/YY";
        phTravellerForm.Controls.Add(tbDOB);
        /**
      tbDOB.Text = this.EditableField.TextValue;
      tbDOB.TextChanged += new EventHandler(tbDOB_OnTextChanged);

      CalendarExtender calExender = new CalendarExtender();
      //calExender.PopupButtonID = "Image1";
      calExender.TargetControlID = tbDOB.ID;
      phTravellerForm.Controls.Add(calExender); **/

        /** End of passport expiry date **/
    }

 protected void btnNext_Click(object sender, EventArgs e)
    {
        TravellerDAL travellerDAL = new TravellerDAL();
        Traveller myTraveller = new Traveller();

        TextBox tbName = phTravellerForm.FindControl("tbName") as TextBox;
        myTraveller.TravellerName = tbName.Text;

        TextBox tbPassport = phTravellerForm.FindControl("tbPassport") as TextBox;
        myTraveller.PassportNumber = tbPassport.Text;
        /**
        CalendarExtender tbPassportExpiry = phTravellerForm.FindControl("tbPassportExpiry") as CalendarExtender;
        myTraveller.PassportExpiryDate = tbPassportExpiry.ToString();
         **/
        TextBox tbNationality = phTravellerForm.FindControl("tbNationality") as TextBox;
        myTraveller.Nationality = tbNationality.Text;
        TextBox tbContact = phTravellerForm.FindControl("tbContact") as TextBox;
        myTraveller.ContactNo = tbContact.Text;

        bool addSuccess = travellerDAL.addTravellerInfo(myTraveller);
        if (addSuccess)
        {
            //No need to bind just saw error messages will do.
            lblAddBookingStatus.Text = "Booking success";
            Response.Redirect("~/TravellerModule/ViewBookingSummary.aspx");
        }
        else
        {
            lblAddBookingStatus.Text = "Oh no! Unable to book please check your entries.";
        }
    }
  • @dotnetom sorry nope. I totally was not even able to retrieve anything from the field – Shirley Charlin Lee Feb 12 '17 at 19:56
  • 2
    When asking a question you shoudl try to be more precise about your error and in particular what line of code actually had the problem. As it is you've given us dozens of lines of code and I have no idea which one is the problem... – Chris Feb 12 '17 at 20:05
  • @Chris as I have mentioned, none of the fields are able to retrieve any value from the user's input. – Shirley Charlin Lee Feb 12 '17 at 21:01

0 Answers0