2016-08-07 7 views
0

私は正常にログインした後、私のmasterpageにログインボタンがあります。私のコンテンツページにloggedUserNameの値を渡したいと思います。とても有難い!下記のフォーラムと呼ばmasterpageからcontentpageに値を渡す方法ASP.Net C#

、継続するか全く分からない: http://forums.asp.net/t/1758733.aspx?Passing+Value+from+Master+page+to+Content+Page

EDITTED:(以下マスターページでは私のコードです)

public partial class MasterPage : System.Web.UI.MasterPage 
{ 
    SqlCommand SQLSelect = new SqlCommand(); 
    SqlConnection SQLCon = new SqlConnection(); 
    DataTable dt = new DataTable("Customer"); 
    int len; 


protected void Page_Load(object sender, EventArgs e) 
{ 
    SQLCon.ConnectionString = ConfigurationManager.ConnectionStrings["SDMConnectionString"].ConnectionString; 
    SQLCon.Open(); 
    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Customer", SQLCon); 
    len = da.Fill(dt); 

    string checking = Request.QueryString["user"]; 

    if (checking != null) 
    { 
     memberview.Visible = true; 
     userview.Visible = false; 
    } 
    else 
    { 
     userview.Visible = true; 
     memberview.Visible = false; 
    } 

    lblLoggedUser.Text = "(" + checking + ")"; 
} 
protected void LoginButton_Click(object sender, EventArgs e) 
{ 
    string username = UserName.Text; 
    string pass = Password.Text; 
    int counter = 0; 
    string content = @"category.aspx?content=" + username; 


    foreach (DataRow row in dt.Rows) 
    { 
     string usernameCheck = row["Username"].ToString(); 
     string passCheck = row["Pass"].ToString(); 

     if (username == usernameCheck && pass == passCheck) 
     { 
      counter = 1; 

      Response.Redirect(content); 
      break; 

     } 
     else 
     { 
      counter = 0; 
     } 

    } 

    if (counter == 1) 
    { 

     Session["user"] = username; 
     lblLoggedUser.Text = Session["user"].ToString(); 

    } 
    else 
    { 
     HttpContext.Current.Response.Write("<script>alert('Error Username or Password!');</script>"); 
    } 

} 

}

+0

ある 'lblLoggedUser.Text =セッション[ "ユーザー"]のToString();のみ' LoginButton_clickで '。 '? – Balah

+0

はい、セッション["user"]の値をラベルに表示するだけです。 @バラ –

答えて

1

一つの方法はにありますページでmasterパラメータを使用し、マスターページから何かを読み取ってください。publicここでは例

マスターページです

public partial class cMasterPage : System.Web.UI.MasterPage 
{ 
    public string getUserName 
    { 
     get 
     { 
      return "what ever"; 
     } 
    } 

    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
} 

ページ

public partial class cPage : System.Web.UI.Page 
{  
    protected void Page_Load(object sender, EventArgs e) 
    { 
     string cGetValue = ((cMasterPage)Master).getUserName; 
    } 
} 
関連する問題