简体   繁体   中英

Changing ASP.Net label's text with VB.Net

I currently have a form that has a label appear when there is an error with changing your password.

Currently there is a bug that makes a message pop up even when the change is successful that says, "Object reference not set to an instance of an object."

I'm wanting to write a test that says when the label is equal to that message to make the visibility false. I've tried:

If lblMsg.Text = "Object reference not set to an instance of an object." Then
            lblMsg.Visible = False
        End If

This, among other variations, have yet to work successfully for me.

Any idea on what other ways I can write this out to hide the label when that message occurs?

Try the following (not the text cannot be null, or this would be a problem):

If lblMsg.Text.ToLower().Trim() = "object reference not set to an instance of an object." Then
            lblMsg.Visible = False
        End If

If that doesn't work, then there is a character off in the message. Alternatively, why not figure out where the object reference error is occurring and fix that problem?

I figured out my error. I ended up having to write an IF statement that checked the response for nulls, ie:

If response Is Nothing OrElse response.length = 0 then
 returnString.AppendLine("Password Changed Successfully.")
 End If 

Thanks to any and all who commented and helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM