1 Replies - 1356 Views - Last Post: 19 April 2017 - 07:23 AM Rate Topic: -----

#1 zyanedwards  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-March 17

Get textbox values from wizard first step

Posted 18 April 2017 - 11:28 PM

Code

    protected void ApplicationWizard_FinishButtonclick(object sender, WizardNavigationEventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["Lml"].ConnectionString;
        SqlConnection conn = null;
        try
        {
            conn = new SqlConnection(connString);
            conn.Open();

            using (SqlCommand cmd = new SqlCommand())
            {
                TextBox fname = AppStep1.FindControl("fname") as TextBox;
                TextBox lname = AppStep1.FindControl("lname") as TextBox;
                TextBox mname = AppStep1.FindControl("mname") as TextBox;

                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "INSERT INTO Borrowers(name) Values (@IsApproved, @DateApplied, @FirstName, @LastName, @MidName)";
                
                cmd.Parameters.AddWithValue("@IsApproved", 0);
                cmd.Parameters.AddWithValue("@DateApplied", DateTime.UtcNow);
                cmd.Parameters.AddWithValue("@FirstName", fname.Text);
                cmd.Parameters.AddWithValue("@LastName", lname.Text);
                cmd.Parameters.AddWithValue("@MidName", mname.Text);

                int rowsAffected = cmd.ExecuteNonQuery();
                if (rowsAffected == 1)
                {
                    success.Text = "Successfully registered!";
                }
                else
                {
                    success.Text = "Registration failed!";
                }
            }
        }
        catch (Exception ex)
        {
            //log error 
            success.Text = "Registration error!" +
                "<br />Error message: " + ex;
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }



All of my textbox controls are in the first step.
When ever I submit the form at the last step an error always shows

Error message
System.NullReferenceException: Object reference not set to an instance of an object. at Borrower_Apply.ApplicationWizard_FinishButtonclick(Object sender, WizardNavigationEventArgs e)

Is This A Good Question/Topic? 0
  • +

Replies To: Get textbox values from wizard first step

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,857
  • Joined: 12-June 08

Re: Get textbox values from wizard first step

Posted 19 April 2017 - 07:23 AM

So slap a break point at the top of that and step through to see where you are trying to use a null/nothing object.

Why would you do this? It seems.. odd.
12            TextBox fname = AppStep1.FindControl("fname") as TextBox;
13            TextBox lname = AppStep1.FindControl("lname") as TextBox;
14            TextBox mname = AppStep1.FindControl("mname") as TextBox;



Where is 'AppStep1' declared? What is its scope?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1