Hello I want to make a button visibile when UserId stored in database match with current UserId.
string clientId = Context.User.Identity.GetUserId();
JobDescriptions job = new JobDescriptions();
if (job.PostedBy == clientId)
{
Button2.Visible = true;
else
{
Button2.Visible = false;
}
PostedBy is the Id of the user who posted on website saved on jobs table. Problem is that button is not visibile when my statement should work.
The solution
if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
int id = Convert.ToInt32(Request.QueryString["id"]);
JobReqModel model = new JobReqModel();
JobDescriptions job = model.GetJob(id);
string clientId = Context.User.Identity.GetUserId();
if (job.PostedBy == clientId)
{
Button2.Visible = true;
}
else
{
Button2.Visible = false;
}
}
!IsPostBack
) - is that your intention?JobDescription
class. You aren't actually getting a job from the database to compare to yourclientId
..so whatever the default value of yourJobDescription
(most likely 0) probably doesn't match yourclientId
.