fwsteal
asked on
HttpContext.Current.Profile null or not present
Need to work with Nulls or if the value is not found.
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile Base p = HttpContext.Current.Profil e;
//firstname
if (p.GetPropertyValue("First Name").ToS tring == null)
{
lblFullName.Text = "firstname";
}
else
{
lblFullName.Text = p.GetPropertyValue("FirstN ame").ToSt ring();
}
How do I write this to check for a null value or if the value
does not exist?
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile
//firstname
if (p.GetPropertyValue("First
{
lblFullName.Text = "firstname";
}
else
{
lblFullName.Text = p.GetPropertyValue("FirstN
}
How do I write this to check for a null value or if the value
does not exist?
ASKER
what if I want to include lastname, email, phone and such?
ASKER
Also, I need to render 'not found' if the value is not located. I tried this but had no luck:
System.Web.Profile.Profile Base p = HttpContext.Current.Profil e;
if (p != null)
{
//firstname
if (p.GetPropertyValue("First Name") == null)
{
lblFirstName.Text = "firstname not found";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN ame").ToSt ring();
}
//lastname
if (p.GetPropertyValue("LastN ame") == null)
{
lblLastName.Text = "lastname not found";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa me").ToStr ing();
}
//email
if (p.GetPropertyValue("Email ").ToStrin g() == null)
{
lblEmail.Text = "email not found";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email" ).ToString ();
}
//job title
if (p.GetPropertyValue("JobTi tle").ToSt ring() == null)
{
lblJobTitle.Text = "jobtitle not found";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit le").ToStr ing();
}
//customer id
if (p.GetPropertyValue("Custo merID").To String() == null)
{
lblCustomerID.Text = "CustomerID not found";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom erID").ToS tring();
}
//account name
if (p.GetPropertyValue("Accou ntName").T oString() == null)
{
lblAccountName.Text = "AccountName not found";
}
else
{
lblAccountName.Text = p.GetPropertyValue("Accoun tName").To String();
}
}
System.Web.Profile.Profile
if (p != null)
{
//firstname
if (p.GetPropertyValue("First
{
lblFirstName.Text = "firstname not found";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN
}
//lastname
if (p.GetPropertyValue("LastN
{
lblLastName.Text = "lastname not found";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa
}
if (p.GetPropertyValue("Email
{
lblEmail.Text = "email not found";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email"
}
//job title
if (p.GetPropertyValue("JobTi
{
lblJobTitle.Text = "jobtitle not found";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit
}
//customer id
if (p.GetPropertyValue("Custo
{
lblCustomerID.Text = "CustomerID not found";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom
}
//account name
if (p.GetPropertyValue("Accou
{
lblAccountName.Text = "AccountName not found";
}
else
{
lblAccountName.Text = p.GetPropertyValue("Accoun
}
}
Hi fwsteal,
You can check it by following way, this will work
if (p.Properties["FirstName"] == null)
{
lblFirstName.Text = "firstname not found";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN ame").ToSt ring();
}
Regards,
NetSwap
You can check it by following way, this will work
if (p.Properties["FirstName"]
{
lblFirstName.Text = "firstname not found";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN
}
Regards,
NetSwap
ASKER
NetSwap,
Here is what I've done thus far and with your suggestion.
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile Base p = HttpContext.Current.Profil e;
if (p != null)
{
//firstname
if (p.GetPropertyValue("First Name") == null)
//if (p.Properties["FirstName"] == null) // nothing is rendered out
{
lblFirstName.Text = "firstname is null";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN ame").ToSt ring();
}
//lastname
if (p.GetPropertyValue("LastN ame") == null)
{
lblLastName.Text = "lastname is null";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa me").ToStr ing();
}
//email
if (p.GetPropertyValue("Email ") == null)
{
lblEmail.Text = "email is null";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email" ).ToString ();
}
//job title
if (p.GetPropertyValue("JobTi tle") == null)
{
lblJobTitle.Text = "jobtitle is null";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit le").ToStr ing();
}
//customer id
if (p.GetPropertyValue("Custo merID") == null)
{
lblCustomerID.Text = "CustomerID is null";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom erID").ToS tring();
}
//account name
if (p.GetPropertyValue("Accou ntName") == null)
{
lblAccountName.Text = " - AccountName is null";
}
else
{
if (p.GetPropertyValue("Accou ntName") == "")
{
lblAccountName.Text = " - AccountName is empty";
}
else
{
lblAccountName.Text = " - " + p.GetPropertyValue("Accoun tName").To String();
}
}
//account type
if (p.GetPropertyValue("Accou ntType") == null)
{
lblAccountType.Text = "(AccountType is null)";
}
else
{
if (p.GetPropertyValue("Accou ntType") == "Parent")
{
lblAccountType.Text = "(Parent Account)";
lkbtnChangeAccount.Text = "Change Account";
lkbtnChangeAccount.PostBac kUrl = "s/sp/changeaccount.aspx";
}
else
{
lblAccountType.Text = "";
}
}
}
}
catch(Exception ex)
{
lblError.Text="Message:" + ex.Message.ToString();
}
}
By check the property collection, I get nothing rendered. Any suggestions?
Here is what I've done thus far and with your suggestion.
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile
if (p != null)
{
//firstname
if (p.GetPropertyValue("First
//if (p.Properties["FirstName"]
{
lblFirstName.Text = "firstname is null";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN
}
//lastname
if (p.GetPropertyValue("LastN
{
lblLastName.Text = "lastname is null";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa
}
if (p.GetPropertyValue("Email
{
lblEmail.Text = "email is null";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email"
}
//job title
if (p.GetPropertyValue("JobTi
{
lblJobTitle.Text = "jobtitle is null";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit
}
//customer id
if (p.GetPropertyValue("Custo
{
lblCustomerID.Text = "CustomerID is null";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom
}
//account name
if (p.GetPropertyValue("Accou
{
lblAccountName.Text = " - AccountName is null";
}
else
{
if (p.GetPropertyValue("Accou
{
lblAccountName.Text = " - AccountName is empty";
}
else
{
lblAccountName.Text = " - " + p.GetPropertyValue("Accoun
}
}
//account type
if (p.GetPropertyValue("Accou
{
lblAccountType.Text = "(AccountType is null)";
}
else
{
if (p.GetPropertyValue("Accou
{
lblAccountType.Text = "(Parent Account)";
lkbtnChangeAccount.Text = "Change Account";
lkbtnChangeAccount.PostBac
}
else
{
lblAccountType.Text = "";
}
}
}
}
catch(Exception ex)
{
lblError.Text="Message:" + ex.Message.ToString();
}
}
By check the property collection, I get nothing rendered. Any suggestions?
you can handle it by otherways as following
if (p.Properties["FirstName"] != null && p.GetPropertyValue("FirstN ame").ToSt ring() != "")
{
lblFirstName.Text = p.GetPropertyValue("FirstN ame").ToSt ring() ;
}
else
{
lblFirstName.Text = "firstname is null or empty";
}
if (p.Properties["FirstName"]
{
lblFirstName.Text = p.GetPropertyValue("FirstN
}
else
{
lblFirstName.Text = "firstname is null or empty";
}
ASKER
I'm running the aspx file with the persistent data on a control file under moss2007 and it renders out nothing when I use: p.Properties["FirstName"]
Wonder why?
Wonder why?
ASKER
Got it:
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile Base p = HttpContext.Current.Profil e;
if (p != null)
{
//firstname
if (p.GetPropertyValue("First Name") != null)
{
if (p.GetPropertyValue("First Name").ToS tring() == null || p.GetPropertyValue("FirstN ame").ToSt ring() == "")
{
lblFirstName.Text = "*FirstName is null or is empty*";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN ame").ToSt ring();
}
}
//lastname
if (p.GetPropertyValue("LastN ame") != null)
{
if (p.GetPropertyValue("LastN ame").ToSt ring() == null || p.GetPropertyValue("LastNa me").ToStr ing() == "")
{
lblLastName.Text = " *LastName is null or is empty* ";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa me").ToStr ing();
}
}
//email
if (p.GetPropertyValue("Email ") != null)
{
if (p.GetPropertyValue("Email ").ToStrin g() == null || p.GetPropertyValue("Email" ).ToString () == "")
{
lblEmail.Text = " *Email is null or is empty* ";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email" ).ToString ();
}
}
//job title
if (p.GetPropertyValue("JobTi tle") != null)
{
if (p.GetPropertyValue("JobTi tle").ToSt ring() == null || p.GetPropertyValue("JobTit le").ToStr ing() == "")
{
lblJobTitle.Text = " *JobTitle is null or is empty* ";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit le").ToStr ing();
}
}
//customer id
if (p.GetPropertyValue("Custo merID") != null)
{
if (p.GetPropertyValue("Custo merID").To String() == null || p.GetPropertyValue("Custom erID").ToS tring() == "")
{
lblCustomerID.Text = " *CustomerID is null or is empty* ";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom erID").ToS tring();
}
}
//account name
if (p.GetPropertyValue("Accou ntName") != null)
{
if (p.GetPropertyValue("Accou ntName").T oString() == null || p.GetPropertyValue("Accoun tName").To String() == "")
{
lblAccountName.Text = " - *AccountName is null or is empty* ";
}
else
{
lblAccountName.Text = p.GetPropertyValue("Custom erID").ToS tring();
}
}
//account type
if (p.GetPropertyValue("Accou ntType") != null)
{
if (p.GetPropertyValue("Accou ntType").T oString() == null || p.GetPropertyValue("Accoun tType").To String() == "")
{
lblAccountType.Text = "(*AccountType is null or is empty*)";
}
else
if (p.GetPropertyValue("Accou ntType") == "Parent")
{
lblAccountType.Text = "(Parent Account)";
lkbtnChangeAccount.Text = "Change Account";
lkbtnChangeAccount.PostBac kUrl = "s/sp/changeaccount.aspx";
}
else
{
lblAccountType.Visible = false;
lkbtnChangeAccount.Visible = false;
}
}
}
}
catch(Exception ex)
{
lblError.Text="Message:" + ex.Message.ToString();
}
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Web.Profile.Profile
if (p != null)
{
//firstname
if (p.GetPropertyValue("First
{
if (p.GetPropertyValue("First
{
lblFirstName.Text = "*FirstName is null or is empty*";
}
else
{
lblFirstName.Text = p.GetPropertyValue("FirstN
}
}
//lastname
if (p.GetPropertyValue("LastN
{
if (p.GetPropertyValue("LastN
{
lblLastName.Text = " *LastName is null or is empty* ";
}
else
{
lblLastName.Text = p.GetPropertyValue("LastNa
}
}
if (p.GetPropertyValue("Email
{
if (p.GetPropertyValue("Email
{
lblEmail.Text = " *Email is null or is empty* ";
}
else
{
lblEmail.Text = p.GetPropertyValue("Email"
}
}
//job title
if (p.GetPropertyValue("JobTi
{
if (p.GetPropertyValue("JobTi
{
lblJobTitle.Text = " *JobTitle is null or is empty* ";
}
else
{
lblJobTitle.Text = p.GetPropertyValue("JobTit
}
}
//customer id
if (p.GetPropertyValue("Custo
{
if (p.GetPropertyValue("Custo
{
lblCustomerID.Text = " *CustomerID is null or is empty* ";
}
else
{
lblCustomerID.Text = p.GetPropertyValue("Custom
}
}
//account name
if (p.GetPropertyValue("Accou
{
if (p.GetPropertyValue("Accou
{
lblAccountName.Text = " - *AccountName is null or is empty* ";
}
else
{
lblAccountName.Text = p.GetPropertyValue("Custom
}
}
//account type
if (p.GetPropertyValue("Accou
{
if (p.GetPropertyValue("Accou
{
lblAccountType.Text = "(*AccountType is null or is empty*)";
}
else
if (p.GetPropertyValue("Accou
{
lblAccountType.Text = "(Parent Account)";
lkbtnChangeAccount.Text = "Change Account";
lkbtnChangeAccount.PostBac
}
else
{
lblAccountType.Visible = false;
lkbtnChangeAccount.Visible
}
}
}
}
catch(Exception ex)
{
lblError.Text="Message:" + ex.Message.ToString();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try
{
System.Web.Profile.Profile
// New check introduced for profile check
if (p!=null)
{
//firstname
if (p.GetPropertyValue("First
{
lblFullName.Text = "firstname";
}
else
{
lblFullName.Text = p.GetPropertyValue("FirstN
}
}