0
votes

am trying to get users to enter some details into a textbox in form1 and get the entry validated against the database. if the entry is correct, form2 loads with other texboxes including the one they made entries into. however i dont want them to make any changes to the textboxes they entered values into previously neither should they have to re-enter the values again.

how do i get the values in the textboxes to move from form1 to form2?

the code below shows what ive done with both forms but the second form dosent display the items in the textboxes when the form is loaded.

first form

protected void Button1_Click(object sender, EventArgs e) { string strConn;

        strConn = "Provider=MIcrosoft.Jet.OLEDB.4.0;data Source=" +
            Server.MapPath("App_Data/test.mdb");

        OleDbConnection mDB = new OleDbConnection(strConn);
        mDB.Open();

        prodSnStr = pSnTextBox.Text;
        purDate = Convert.ToDateTime(purDateTextBox.Text);
        string dateStr = purDateTextBox.Text;

        productClass aProduct = new productClass();

        if (aProduct.Prods(mDB, prodSnStr, purDate))
        {
            Session["ProdSn"] = pSnTextBox.Text;
            Session["PurDate"] = purDateTextBox.Text.ToString();

            Response.Redirect("Warranty.aspx");

        }
        else
        {
            //error message
        }
     }

form two

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["ProdSn"] != "")
            {
                pSNoTextBox.Text = Request.QueryString["ProdSn"];

                if (Request.QueryString["PurDate"] != "")
                {
                    dateTextBox.Text = Request.QueryString["PurDate"];
                }
                else
                {
                    //error message to display
                }

            }
            else
            {
                //error message to display
            }
        }

eagaerly waiting for your responses..thanks..

4

4 Answers

2
votes

In your code you are putting the values on one page into the session:

    Session["ProdSn"] = pSnTextBox.Text;
    Session["PurDate"] = purDateTextBox.Text.ToString();

However you are trying to read them out on the 2nd page from the Request collection:

    if (Request.QueryString["ProdSn"] != "")
    {
         pSNoTextBox.Text = Request.QueryString["ProdSn"];
    if (Request.QueryString["PurDate"] != "")
    {
         dateTextBox.Text = Request.QueryString["PurDate"];
    }

This makes no sense. If you want to use the session, you must also get the values back out from the session object.

Personally I would look into Cross Page postbacks and Server.Transfer combined with Page.PreviousPage. Just make sure you don't set preserveForm parameter to false if using Server.Transfer.

0
votes

You aren't passing your values as a query string. If you were your Response.Redirect would look like this:

Response.Redirect("Warranty.aspx?ProdSn=something&PurDate=something");

Instead since you are saving these values in a Session variable try this:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (Session["ProdSn"] != "")
        {
            pSNoTextBox.Text = Session["ProdSn"];

            if (Session["PurDate"] != "")
            {
                dateTextBox.Text = Session["PurDate"];
            }
            else
            {
                //error message to display
            }

        }
        else
        {
            //error message to display
        }
    }
0
votes

In the button_click of the first form i entered this code

Session["ProdSn"] = pSnTextBox.Text; Session["PurDate"] = purDateTextBox.Text.ToString();

Response.Redirect("Warranty.aspx?ProdSn=" + Server.UrlEncode(pSnTextBox.Text) + "&PurDate=" + Server.UrlEncode(purDateTextBox.Text));

and then in the Page_load event of the second form i did this..

string value = Request["ProdSn"]; string value1 = Request["PurDate"]; pSnTextBox.Text = value; purDateTextBox.Text = value1;

no hassle sustained....easy and perfectly working....

thank for ya'11 helping.... am very grateful

-1
votes

your asp.net page must post your data to second page. just set your buttons PostBackUrl attribute.

<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="target.aspx" />

I do not understand while you are making things complex. When users clicks the button all data will be send to your target page.