2010-01-21 59 views
2

也許它的東西,小我沒有看到...... 我有一個UserControls_LoginPopUp與屬性之一爲:爲什麼空(登錄彈出)

public string urlForRedirecting {get; set;} 

這個用戶控件包含modalpopupextender和方法登錄:

public void Login_Click(object sender, EventArgs e) 
{ 
    string user = txtUser.Text; 
    string passwordMD5 = UtilsStatic.GetMD5Hash(txtPassword.Text); 
    int id = checkUserAtLogin(user, passwordMD5); 
    if (id != -1) 
    { 
     //MySession.Current.userId = id; 
     lblStatus.Text = "Autentificare reusita!"; 
     loginPopUp.Hide(); 

     //The user will be redirected 
     Response.Redirect(this.urlForRedirecting); 
     this.urlForRedirecting = ""; 
    } 
    else 
    { 
     MySession.Current.userId = -1; 
     lblStatus.Text = "Autentificare esuata!"; 
     loginPopUp.Show(); 
    } 
} 

現在,從另一個頁面,用戶點擊一個鏈接,一種方法,其中顯示的模式擴展,所以他可以登錄解僱。請注意,我填補了urlForRedirecting屬性:

public void redirectToWishList(object sender, EventArgs e) 
{ 
    if (UtilsStatic.getUserLoggedInId() == -1) 
    { 
     ASP.usercontrols_loginpopup_ascx loginUserControl = (ASP.usercontrols_loginpopup_ascx)UtilsStatic.FindControlRecursive(Page, "loginPopUp"); 
     ModalPopupExtender modal = (ModalPopupExtender)loginUserControl.FindControl("loginPopUp"); 
     modal.Show(); 
     //put the link to which the redirect will be done if the user will succesfully login in 
     loginUserControl.urlForRedirecting = getWishListLink(); 
    } 
    else 
     Response.Redirect(getWishListLink()); 

} 

的問題是,在成功地將userr登錄後,該URL爲null(但我已經完成了它已經!!!)

Response.Redirect(this.urlForRedirecting); 

你明白爲什麼了嗎?

回答

0

當你打的代碼行:

modal.Show(); 

您的用戶控件將被顯示,並設置在此之後的值,使窗體打開時,它沒有設置。

嘗試移動代碼,以便它像:

ASP.usercontrols_loginpopup_ascx loginUserControl = (ASP.usercontrols_loginpopup_ascx)UtilsStatic.FindControlRecursive(Page, "loginPopUp"); 
loginUserControl.urlForRedirecting = getWishListLink(); 
ModalPopupExtender modal = (ModalPopupExtender)loginUserControl.FindControl("loginPopUp"); 
modal.Show(); 

打開表前,這將設置urlForRedirecting屬性,這意味着一旦它是開放的,你可以訪問它。

+0

嗨Fermin。我已經移動了代碼,但也存在同樣的問題。然而,urlForRedirecting是loginUserControl的一個屬性,所以它不依賴於.show。無論如何,謝謝你的建議。 – 2010-01-21 18:47:05

+1

嘗試使urlForRedirecting靜態,因爲當您回發時該值將會丟失。 – Fermin 2010-01-21 19:42:39

+0

您的評論是有幫助的。儘管它沒有回答我的問題,但它給了我一個在這種情況下使用靜態類的理念。謝謝。 – 2010-01-21 20:10:21

0

在回傳之間使用ViewState,否則屬性值將丟失。

public string UrlForRedirecting 
{ 
    get 
    { 
     object urlForRedirecting = ViewState["UrlForRedirecting"]; 
     if (urlForRedirecting != null) 
     { 
      return urlForRedirecting as string; 
     } 

     return string.Empty; 
    } 

    set 
    { 
     ViewState["UrlForRedirecting"] = value; 
    } 
} 
1

您應該隨時修改用戶名/密碼的值以刪除空格。

string user = txtUser.Text.Trim(); 
string passwordMD5 = UtilsStatic.GetMD5Hash(txtPassword.Text.Trim()); 

我相信,如果你有「價值」與「價值」,GetMD5Hash將創建不同的值。

+0

感謝loxp。非常有用! – 2010-01-23 19:29:58