2017-01-03 44 views
1

我正在使用具有繼承母版頁的「註冊和登錄」頁的網站。在這項工作中,我希望應用程序在新用戶嘗試註冊時檢查數據庫中是否存在電子郵件,如果電子郵件存在,它將重定向到登錄頁面並在登錄頁面的標籤上顯示消息。使用FindControl在另一頁上查找控件

我的檢查代碼正在工作。 但我的問題是,我無法找到登錄頁面中的標籤控件,我需要幫助。下面 是我在註冊頁面代碼:

登錄aspx頁面上的標籤ID是eMailExist

if (dt.Rows.Count > 0) 
{ 
    Response.Redirect("~/Login.aspx"); 
    Label Exist = (Label)Master.FindControl("eMailExist"); 
    Exist.Text = "eMail already in use, try Loging in"; 
} 
+0

的頁面加載,可以儲存你的條件雪村,查詢字符串...並設置在登錄頁面的標籤。 –

+0

'Response.Redirect'後面的代碼不會被執行,我已經發布了一個很好的建議來解決這個問題,請看一看 –

回答

0

我認爲這不會鍛鍊,因爲代碼後,因爲它加載LoginResponse.Redirect不會執行,但我有一個好主意,你用一些查詢字符串參數更新登錄頁面標籤,這將是這樣的:

的重定向將是這樣的:

Response.Redirect("~/Login.aspx?MsgCode=1"); 

而且你必須添加以下的login.aspx.cs

if (!IsPostBack) 
{ 
    string messageCode = Request.QueryString["MsgCode"]; 
    if (!string.IsNullOrEmpty(messageCode)) 
    { 
     switch (messageCode) 
     { 
      case "1" : 
       lbleMailExist.Text = "eMail already in use, try Loging in"; 
       break; 
      case "2" : 
       lbleMailExist.Text = "Operation time-out, try Loging in"; 
       break; 
       // populate conditions 
      default: 
       break; 
     } 
    } 
} 
+0

我使用了你的代碼,它工作正常。非常感謝 –

+0

很高興聽到它的幫助。希望你不會忘記將它標記爲[accepted](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) –