Checking for null.......
Checking for null.......
(OP)
I've tried two ways to check for null and neither work:
I have a menu control and when I click a link the below event is fired. I tried two ways to check for null and neither work. Can someone please help?
protected void MenuItems_OnMenuItemClick(object sender, MenuEventArgs e)
{
try
{
if ( e.Item.Text != null)
{
Debug.WriteLine("MenuItem: " + e.Item.Text );
}
}
catch(Exception ex)
{
throw (ex);
}
}
And:
protected void MenuItems_OnMenuItemClick(object sender, MenuEventArgs e)
{
try
{
System.Web.UI.WebControls.MenuItem mi = new System.Web.UI.WebControls.MenuItem();
if (mi.Parent.Text != null)
{
Debug.WriteLine("MenuItem: " + e.Item.Text );
}
}
catch(Exception ex)
{
throw (ex);
}
}
RE: Checking for null.......
if (!string.IsNullOrEmpty(mi.Parent.Text))
{
code
}
RE: Checking for null.......
RE: Checking for null.......
RE: Checking for null.......
?e.Item.Parent.Parent.Text
'e.Item.Parent' is null
Step into: Stepping over non-user code 'System.Web.UI.WebControls.MenuEventArgs.Item.get'
A first chance exception of type 'System.NullReferenceException' occurred in App_Web_fjsl66dx.dll
A first chance exception of type 'System.NullReferenceException' occurred in App_Web_fjsl66dx.dll
RE: Checking for null.......
Try with:
if (e.Item.Parent != null && !string.IsNullOrEmpty(e.Item.Parent.Text))
{
code
}
RE: Checking for null.......
RE: Checking for null.......
RE: Checking for null.......