I have created a webforms application for a micro-insurance business. In one of my forms, I added a button which redirects a user to page where he can sell insurance. Each user has a credit limit. Once reached, the idea is that the button which redirects to selling will be invisible.
I was able to get the credit limit from the database. My problem is how can I hide or show the button if the condition is satisfied. Below is my design and snipets of my code behind. I'm still new in programming.
- public partial class credit_limit : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- lblUserName.Text = Session["username"].ToString();
- lblDepartment.Text = Session["department"].ToString();
-
- if(!IsPostBack)
- {
- viewCreditLimit();
- }
-
- }
-
- protected void btnMotor_Click(object sender, EventArgs e)
- {
-
- }
-
-
- private void viewCreditLimit()
- {
- using (SqlConnection con = DBConn.GetDbCon())
- {
- con.Open();
- SqlCommand cmd = new SqlCommand("select CreditLimit from Login where UserName = @UserName and DepartmentID=@DepartmentID", con);
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.AddWithValue("@UserName", lblUserName.Text);
- cmd.Parameters.AddWithValue("@DepartmentID", lblDepartment.Text);
-
- using (SqlDataReader rdr = cmd.ExecuteReader())
- {
- try
- {
- while (rdr.Read())
- {
- lblcreditlimit.Text = rdr["CreditLimit"].ToString();
- }
-
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
-
- }
- }
-
- private void showButton()
- {
- if (lblcreditlimit.Text < lblcreditlimit.Text)
- {
- Panel1.Visible = true;
- }
- else
- {
- Panel1.Visible = false;
- lblMessage.Text = "Your credit limit is already reached.";
- }
- }
- }