2010-01-21 58 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