none
Querystring not passing RRS feed

  • Question

  • Hi folks,

    I’m trying to pass the OrderID through a querystring, but it is not passing the value,

    URL from the second page;

     Invoice.aspx?ProdID=6&OrdID=System.Web.UI.WebControls.TextBox

    Code below any advice much appreciated

     string connectionString = ConfigurationManager.ConnectionStrings["TyreSannerSQLConnectionString"].ConnectionString;
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("AddCustomerDetails", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Forename", SqlDbType.VarChar, 50).Value = txtCusForename.Text;
            cmd.Parameters.Add("@Surname", SqlDbType.VarChar, 50).Value = txtCusSurename.Text;
            cmd.Parameters.Add("@HouseNo", SqlDbType.VarChar, 50).Value = txtHouseNo.Text;
            cmd.Parameters.Add("@CustAddress", SqlDbType.VarChar, 50).Value = txtAddress.Text;
            cmd.Parameters.Add("@Town", SqlDbType.VarChar, 50).Value = txtTown.Text;
            cmd.Parameters.Add("@Postcode", SqlDbType.VarChar, 50).Value = txtPostcode.Text;
            cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 50).Value = txtContactNo.Text;
            cmd.Parameters.Add("@EmailAddress", SqlDbType.VarChar, 50).Value = txtEmailAddress.Text;
            cmd.Parameters.Add("@ProductQuantity", SqlDbType.Int).Value = txtQuantity.Text;
            cmd.Parameters.Add("@TotalProductSaleCost", SqlDbType.Decimal).Value = Convert.ToDouble(txtTotalAmount.Text);
            cmd.Parameters.Add("@ProductFK", SqlDbType.Int).Value = txtProductID.Text;
            cmd.Parameters.Add("@FittingDate", SqlDbType.Date).Value = Convert.ToDateTime(txtFittingDate.Text);
            cmd.Parameters.Add("@FittingTime", SqlDbType.Time).Value = TimeSpan.Parse(txtFittingTime.Text);
            //cmd.Parameters.Add("@TotalProductSaleCost", SqlDbType.Decimal).Value = Convert.ToDouble(txtTotalAmount);
            //cmd.Parameters.Add("@AnyAdditionalInfo", SqlDbType.VarChar, -1).Value = txtAdditionalInformation.Text;
            //cmd.Parameters.Add("@HouseNo", SqlDbType.Int, yourInt);
            string returnValue;
            try
            {
                con.Open();
                returnValue = cmd.ExecuteScalar().ToString();
                txtOrderID.Text = returnValue;
                insertReportLabel.Text = "Student inserted sucessfully";
            }
            catch
            {
                insertReportLabel.Text = "Student NOT inserted";
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
            {
                Response.Redirect("~/Pages/Invoice.aspx?ProdID=" + txtProductID.Text + "&OrdID=" + txtOrderID);
            }
            
        }
       
    }

    Second page code

    public partial class Pages_Invoice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) // Execute this code, only on the first load, when it is NOT postback from other server control.
            {
                txtProductID.Text = Request.QueryString["ProdID"];
                txtOrderID.Text = Request.QueryString["OrdID"];
            }
        }
    }


    • Edited by brucey54 Thursday, November 13, 2014 4:46 PM
    Thursday, November 13, 2014 4:42 PM

Answers

  • You missed .Text off:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" +

    txtProductID.Text + "&OrdID=" + txtOrderID.Text);


    • Marked as answer by brucey54 Thursday, November 13, 2014 5:21 PM
    Thursday, November 13, 2014 4:46 PM
    Moderator
  • Fix that:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" + txtProductID.Text + "&OrdID=" + txtOrderID);

    To:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" + txtProductID.Text + "&OrdID=" + txtOrderID.Text);

    • Proposed as answer by Deric Ferreira Thursday, November 13, 2014 4:47 PM
    • Marked as answer by brucey54 Thursday, November 13, 2014 5:22 PM
    Thursday, November 13, 2014 4:47 PM

All replies

  • You missed .Text off:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" +

    txtProductID.Text + "&OrdID=" + txtOrderID.Text);


    • Marked as answer by brucey54 Thursday, November 13, 2014 5:21 PM
    Thursday, November 13, 2014 4:46 PM
    Moderator
  • Fix that:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" + txtProductID.Text + "&OrdID=" + txtOrderID);

    To:

    Response.Redirect("~/Pages/Invoice.aspx?ProdID=" + txtProductID.Text + "&OrdID=" + txtOrderID.Text);

    • Proposed as answer by Deric Ferreira Thursday, November 13, 2014 4:47 PM
    • Marked as answer by brucey54 Thursday, November 13, 2014 5:22 PM
    Thursday, November 13, 2014 4:47 PM
  • Thanks, home time I think :)
    Thursday, November 13, 2014 5:22 PM