Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2005, 06:39 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Don't know where have gone wrong

Hi, I get this error:

Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 58: Response.Write("Please type the same new password")
Line 59: End If
Line 60:
Line 61: If Page.IsValid Then
Line 62: Dim con As SqlConnection


Source File: c:\inetpub\wwwroot\e-library\UserPassword.aspx.vb Line: 60

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   e_library.UserPassword.btnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-library\UserPassword.aspx.vb:60
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain() +1292




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Code:
 Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim NewPwd As String
        Dim RetypePwd As String
        NewPwd = NewPwd.Trim
        RetypePwd = RetypePwd.Trim

        If NewPwd.Length < 4 Or NewPwd.Length > 10 Then
            Response.Write("Password must be 4-10 characters!")
        End If

        If RetypePwd <> NewPwd Then
            Response.Write("Please type the same new password")
        End If

        If Page.IsValid Then
            Dim con As SqlConnection
            Dim sql As String
            Dim cmd As SqlCommand
            Dim sb As New StringBuilder
            Dim values As New ArrayList

            sb.Append("UPDATE [User] SET ")
            sb.Append("User_id='{0}', User_Password='{1}'")

            values.Add(txtUserID.Text)
            values.Add(txtNewPwd.Text)

            values.Add(Context.User.Identity.Name)
            sql = String.Format(sb.ToString(), values.ToArray())

            con = New SqlConnection( _
                "data source=(local)\NetSdk;initial catalog=E-Library Records;user id=sa")

            cmd = New SqlCommand(sql, con)
            con.Open()

            Try
                cmd.ExecuteNonQuery()
            Catch ex As Exception
                lblMessage.Visible = True
                lblMessage.Text = "Couldn't change your password."
            Finally
                con.Close()
            End Try
            lblPasswordMessage.Visible = True
            lblPasswordMessage.Text = "You have changed your password successfully."
        End If
    End Sub
Hope somebody can help me.

Thanks!

Irene

 
Old May 20th, 2005, 07:06 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This wont work :
        Dim NewPwd As String //here you are declaring the variables
        Dim RetypePwd As String
        NewPwd = NewPwd.Trim //there is no value in the variable NewPwd.
        RetypePwd = RetypePwd.Trim //why are u performing a trim if there is no value in the variable?

       //here u have no value in NewPwd and u are trying to find its length
       //this wont work!
       If NewPwd.Length < 4 Or NewPwd.Length > 10 Then
            Response.Write("Password must be 4-10 characters!")
        End If

You need to assign the values from the appropriate controls into the
variables NewPwd and RetypePwd









Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong ??? FT BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 3rd, 2005 09:18 AM
Help..What am I doing wrong... Brettvan1 VB.NET 2002/2003 Basics 2 October 18th, 2004 02:36 AM
Where did I go wrong??? ahc2inc VB.NET 2002/2003 Basics 3 September 28th, 2004 08:19 PM
What's wrong?Help! amu BOOK: Beginning ASP.NET 1.0 1 October 28th, 2003 08:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.