Posted this on Asp.Net, seems to be a hard problem, I still can't work it out
I have a edit button, this works fine, until I add the code that prevents the edit button from being seen by users who did not post that ticket. I cannot understand why this is happening. I get an error on the button says 'object reference not set in instance of object'
It happens when I add the following code:
-
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
-
{
-
HiddenField commentidfield = e.Item.FindControl("commentidfield") as HiddenField;
-
HiddenField userloginfield = e.Item.FindControl("userloginfield") as HiddenField;
-
-
ImageButton votebutton = e.Item.FindControl("commentvotebutton") as ImageButton;
-
ImageButton editbutton = e.Item.FindControl("editbutton") as ImageButton;
-
-
-
-
if (HttpContext.Current.User.Identity.IsAuthenticated == true)
-
{
-
int commentidtemp = Convert.ToInt32(commentidfield.Value);
-
int userloginid = Convert.ToInt32(userloginfield.Value);
-
-
int commentcheck = Convert.ToInt32(commentratingclass.CheckCommentVote(Profile.userid, commentidtemp).GetValueOrDefault(0));
-
int editcheck = Convert.ToInt32(commentclass.checkcommentbyuserid(Profile.userid, commentidtemp).GetValueOrDefault(0));
-
-
-
if (userloginid == Profile.userid)
-
{
-
votebutton.Visible = false;
-
}
-
else if (commentcheck > 0)
-
{
-
votebutton.ImageUrl = "Images/commentvoted.png";
-
votebutton.Enabled = false;
-
}
-
else
-
{
-
votebutton.ImageUrl = "Images/commentvote.png";
-
votebutton.Enabled = true;
-
}
-
-
if (editcheck == 0)
-
{
-
editbutton.Visible = false;
-
}
-
else
-
{
-
editbutton.Visible = true;
-
}
-
}
-
else
-
{
-
votebutton.Visible = false;
-
editbutton.Visible = false;
-
}
-
-
-
}
-
-
-
Listview: