2017-06-02 14 views
0

ケースが発生したときにlblsourceとlblmessageを変更しようとしています。どうすればいいですか? lblsourceとlblmessageの.text値にログインするときケースが発生したときにラベルテキストを変更します

<div class="form-horizontal well container-cus">   
<div class="row">    
<div class="col-lg-12">     
<br />     
<br />     
<div style="width: 350px; box-shadow: 5px 0px 40px rgba(0,0,0, .2);" class="panel panel-warning center-block">      
<div class="panel-heading"> 
</div>      
<div class="panel-body">       
<div class="form-group">        
<div class="row">         
<div class="text-center">          
<img class="profile-img" src="/Images/user_icon.png" />         
</div>        
</div>        
<br />        
<div class="row">         
<div class="col-lg-12">          
<asp:TextBox ID="txtUsername" CssClass="form-control" placeholder="Username" runat="server" required></asp:TextBox>         
</div>        
</div>       
</div>       
<div class="form-group">        
<div class="row">         
<div class="col-lg-12">          
<asp:TextBox ID="txtPassword" class="form-control" placeholder="Password" runat="server" TextMode="Password" required></asp:TextBox>         
</div>        
</div>       
</div>       
<br />       
<br />       
<div class="panel-footer">        
<div class="row">         
<div class="col-lg-12">          
<asp:Button ID="btnLogin" Style="width: 290px;" class="btn btn-warning btn-lg pull-right" runat="server" Text="LOGIN" OnClick="btnLogin_Click" />         
</div>        
</div>       
</div>      
</div>      
<asp:Label ID="lblsource" runat="server" CssClass="text-danger" Text=""></asp:Label>      
<br />      
<asp:Label ID="lblmessage" runat="server" CssClass="text-danger" Text=""></asp:Label>      
<br />      
<asp:Label ID="Label1" runat="server" CssClass="text-danger" Text="Invalid Username or Password" Visible="false"></asp:Label>     
</div>        
</div>   
</div>  
</div> 

上記のコードは私の.aspxのある、それはswitch文で、特定のケースに入ったときの変化でなければなりません

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using System.Data.SqlClient; 

public partial class Account_Suppliers_Login : System.Web.UI.Page 
{ 
    protected void btnLogin_Click(object sender, EventArgs e) 
    { 
     using (SqlConnection con = new SqlConnection(Helper.GetCon())) 
     { 
      con.Open(); 
      SqlCommand cmd = new SqlCommand("SELECT su.SupplierID, su.Status, ut.Username, ut.Password, ut.UserID FROM UserTable ut INNER JOIN Suppliers su ON su.UserID = ut.UserID Where ut.Username = '" + txtUsername.Text + "' AND ut.Password = '" + Helper.CreateSHAHash(txtPassword.Text) + "'", con); 

      SqlDataReader dr = cmd.ExecuteReader(); 
      if (dr.HasRows) 
      { 
       while (dr.Read()) 
       { 
        Session["SupplierID"] = dr["SupplierID"].ToString(); 
        Session["Status"] = dr["Status"].ToString(); 
        Session["Username"] = dr["Username"].ToString(); 
        Session["UserID"] = dr["UserID"].ToString(); 
       } 

       string statuscode = Session["Status"].ToString(); 


       switch (statuscode) 
       { 
        case "Active": 
         Session["Status"] = null; 
         Session.Remove("Status"); 
         Response.Redirect("\\Account\\Suppliers\\Default.aspx"); 
         break; 

        case "Inactive": 

         lblsource.Text = "Login Page: INACTIVE"; 
         lblmessage.Text = "Welcome Back! Please let us know on how we can help you better."; 
         Response.Redirect("\\Account\\Suppliers\\Login.aspx"); 
         break; 

        case "Pending": 
         lblsource.Text = "Login Page: PENDING"; 
         lblmessage.Text = "Thank you for registering with us. We will process your request shortly."; 
         lblsource.Visible = true; 
         lblmessage.Visible = true; 

         Response.Redirect("\\Account\\Suppliers\\Login.aspx"); 
         break; 

        case "Blocked": 
         lblsource.Text = "Login Page: BLOCKED"; 
         lblmessage.Text = "We are so glad to hear from you. Please settle your account."; 
         lblsource.Visible = true; 
         lblmessage.Visible = true; 
         Response.Redirect("\\Account\\Suppliers\\Login.aspx"); 
         break; 
       } 

      } 
      else 
      { 
       Label1.Visible = true; 
      } 




    } 

    private DataSet GetRecordSuppplier(string TableName) 
    { 
     using (SqlConnection con = new SqlConnection(Helper.GetCon())) 
     { 
      SqlCommand cmd = new SqlCommand(); 
      cmd.Connection = con; 
      cmd.CommandType = CommandType.Text; 
      cmd.CommandText = "SELECT * FROM " + TableName + " WHERE SupplierID = '" + Session["SupplierID"] + "'"; 
      SqlDataAdapter da; 
      da = new SqlDataAdapter(); 
      da.SelectCommand = cmd; 

      DataSet ds = new DataSet(); 
      da.Fill(ds, TableName); 

      return ds; 
       } 
} 

上記のコードは私のです。 aspx.cs 大文字と小文字の区別がある場合にlblsourceとlblmessageの値を変更したいだけです

答えて

0

Response.Redirectあなたは同じページにとどまっていますか?デフォルトへのリダイレクトは意味がありますが、すでにログインページにあるように、ログインページにリダイレクトすることはできません。

これらのリダイレクトを削除してページを処理させると、期待通りに適用されたラベルの更新が表示されます。

0

あなたのボタンクリックのコードはこれを好む必要があります。

protected void btnLogin_Click(object sender, EventArgs e) 
    { 
     using (SqlConnection con = new SqlConnection(Helper.GetCon())) 
     { 
      con.Open(); 
      SqlCommand cmd = new SqlCommand("SELECT su.SupplierID, su.Status, ut.Username, ut.Password, ut.UserID FROM UserTable ut INNER JOIN Suppliers su ON su.UserID = ut.UserID Where ut.Username = '" + txtUsername.Text + "' AND ut.Password = '" + Helper.CreateSHAHash(txtPassword.Text) + "'", con); 

      SqlDataReader dr = cmd.ExecuteReader(); 
      if (dr.HasRows) 
      { 
       while (dr.Read()) 
       { 
        Session["SupplierID"] = dr["SupplierID"].ToString(); 
        Session["Status"] = dr["Status"].ToString(); 
        Session["Username"] = dr["Username"].ToString(); 
        Session["UserID"] = dr["UserID"].ToString(); 
       } 

       string statuscode = Session["Status"].ToString(); 


       switch (statuscode) 
       { 
        case "Active": 
         Session["Status"] = null; 
         Session.Remove("Status"); 
         Response.Redirect("\\Account\\Suppliers\\Default.aspx"); 
         break; 

        case "Inactive": 

         lblsource.Text = "Login Page: INACTIVE"; 
         lblmessage.Text = "Welcome Back! Please let us know on how we can help you better."; 

         break; 

        case "Pending": 
         lblsource.Text = "Login Page: PENDING"; 
         lblmessage.Text = "Thank you for registering with us. We will process your request shortly."; 
         lblsource.Visible = true; 
         lblmessage.Visible = true; 


         break; 

        case "Blocked": 
         lblsource.Text = "Login Page: BLOCKED"; 
         lblmessage.Text = "We are so glad to hear from you. Please settle your account."; 
         lblsource.Visible = true; 
         lblmessage.Visible = true; 

         break; 
       } 

      } 
      else 
      { 
       Label1.Visible = true; 
      } 




    } 
関連する問題