Asp.net visible button when 2 parameters match

106 views Asked by At

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;
                }
            }
0

There are 0 answers