473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why GetUser getting NullReferenceException???

I'm creating my own create user wizard.

Here's my code...
If Membership.GetUser(txtEzUsername.Text).ProviderUse rKey.ToString
<"" Then
Me.lblStatus.Text = "Username is in use. Please select another
Username."
Exit Sub
End If

Here's the error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_5nh_bhxb"
StackTrace:
at NewUserWizard.cmdCreate_Click(Object sender, EventArgs e) in
F:\work-related\websites\Lexitel\NewUserWizard.aspx.vb:lin e 87 at
System.Web.UI.WebControls.Button.OnClick(EventArgs e) at
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl,
String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) at
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint)
InnerException:

How can I check if GetUser returns nothing (ie the user doesnt exist)?

Thanks.
Jul 26 '08 #1
3 2019
You are blowing up on this part:

..ProviderUserKey.ToString

You can avoid this by doing this:

Dim user As MembershipUser = Membership.GetUser(txtEzUsername.Text)

If user is nothing then
'There is no user
Else
'Do what you want
End if

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"Cirene" <ci****@nowhere.comwrote in message
news:Od**************@TK2MSFTNGP02.phx.gbl...
I'm creating my own create user wizard.

Here's my code...
If Membership.GetUser(txtEzUsername.Text).ProviderUse rKey.ToString
<"" Then
Me.lblStatus.Text = "Username is in use. Please select another
Username."
Exit Sub
End If

Here's the error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_5nh_bhxb"
StackTrace:
at NewUserWizard.cmdCreate_Click(Object sender, EventArgs e) in
F:\work-related\websites\Lexitel\NewUserWizard.aspx.vb:lin e 87 at
System.Web.UI.WebControls.Button.OnClick(EventArgs e) at
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl,
String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

How can I check if GetUser returns nothing (ie the user doesnt exist)?

Thanks.
Jul 26 '08 #2
Cirene wrote:
I'm creating my own create user wizard.

Here's my code...
If Membership.GetUser(txtEzUsername.Text).ProviderUse rKey.ToString
<"" Then
Me.lblStatus.Text = "Username is in use. Please select another
Username."
Exit Sub
End If

Here's the error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_5nh_bhxb"
StackTrace:
at NewUserWizard.cmdCreate_Click(Object sender, EventArgs e) in
F:\work-related\websites\Lexitel\NewUserWizard.aspx.vb:lin e 87 at
System.Web.UI.WebControls.Button.OnClick(EventArgs e) at
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl,
String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) at
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint)
InnerException:

How can I check if GetUser returns nothing (ie the user doesnt exist)?

Thanks.


The statement
If Membership.GetUser(txtEzUsername.Text).ProviderUse rKey.ToString

expects that a user will be found. The .ProviderUserKey.ToString
expects a user object so you will have to test the
Membership.GetUser(txtEzUsername.Text) for nothing before you attempt to
use the object.

I would suggest a two step statement, the first to attempt to populate a
user object and if it is not nothing then do the .ProviderUserKey etc.

LS
Jul 26 '08 #3
Thanks Cowboy and Lloyd (and everyone else)!

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:ua**************@TK2MSFTNGP02.phx.gbl...
You are blowing up on this part:

.ProviderUserKey.ToString

You can avoid this by doing this:

Dim user As MembershipUser = Membership.GetUser(txtEzUsername.Text)

If user is nothing then
'There is no user
Else
'Do what you want
End if

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"Cirene" <ci****@nowhere.comwrote in message
news:Od**************@TK2MSFTNGP02.phx.gbl...
>I'm creating my own create user wizard.

Here's my code...
If Membership.GetUser(txtEzUsername.Text).ProviderUse rKey.ToString
<"" Then
Me.lblStatus.Text = "Username is in use. Please select another
Username."
Exit Sub
End If

Here's the error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_5nh_bhxb"
StackTrace:
at NewUserWizard.cmdCreate_Click(Object sender, EventArgs e) in
F:\work-related\websites\Lexitel\NewUserWizard.aspx.vb:lin e 87 at
System.Web.UI.WebControls.Button.OnClick(EventArg s e) at
System.Web.UI.WebControls.Button.RaisePostBackEve nt(String eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IP ostBackEventHandler.RaisePostBackEvent(String
eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEv entHandler
sourceControl, String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(NameValueCo llection postData) at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

How can I check if GetUser returns nothing (ie the user doesnt exist)?

Thanks.

Jul 26 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
5
by: Fabio Papa | last post by:
Hi, I am fairly new to programming and and even newer to dotnet. I appoligise in advance if this is a dumb questions, and I would appreciate if you could answer it anyways. :) I am writing a...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
2
by: Jav | last post by:
I need to get at the ProviderUserKey of the logged in user. I would have thought that I could do something like: Dim u As MembershipUser = Membership.GetUser Dim ProvKey as Guid =...
6
by: David Lozzi | last post by:
Hello there, I'm getting the following error System.NullReferenceException: Object reference not set to an instance of an object. at shopping_bag.GetBagTotals()
3
by: Nightcrawler | last post by:
Hi, I have a blog in my application that any registered user can post to (I am using Microsoft's Memberships and Profiles for this). When I show the blog entries in a datalist I also want to...
1
by: RamyaBhaskaran | last post by:
I have created an application inwhich in the form i have written the following code namespace WindowsApplication5 { public partial class Form1 : Form { public Form1() ...
4
by: Cirene | last post by:
Using asp.net membership. My login.aspx page goes to the loginredirect.aspx page after the user logs in. For some reason "Membership.GetUser.ProviderUserKey.ToString" gives me this error:...
2
by: Florian Paulus | last post by:
Hello group, i'm trying to load some additionally stored information to a user at login time. That data is self created and stored in an sql database. I hooked in the login control...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.