why null (login pop up)
Probably it's something small i do not see... I have a UserControls_LoginPopUp with one of the properti开发者_StackOverflow社区es as:
public string urlForRedirecting {get; set;}
This user control contains a modalpopupextender and a method for login:
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();
}
}
Now, from another page, a user clicks a link, and a method is fired where the modal extender is shown so he can login. Please notice that i fill up the urlForRedirecting property:
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());
}
The problem is that, after the userr logs in succesfully, the url is null (but i've completed it already!!!)
Response.Redirect(this.urlForRedirecting);
Do you see why?
You should always trim your values for username/passwords to remove white space.
string user = txtUser.Text.Trim();
string passwordMD5 = UtilsStatic.GetMD5Hash(txtPassword.Text.Trim());
I believe that GetMD5Hash will create diffrent values if you have "Value" vs " Value ".
When you hit the line of code:
modal.Show();
Your user control will be shown and you set the value after this so it's not set when the form opens.
Try moving the code so that it's like:
ASP.usercontrols_loginpopup_ascx loginUserControl = (ASP.usercontrols_loginpopup_ascx)UtilsStatic.FindControlRecursive(Page, "loginPopUp");
loginUserControl.urlForRedirecting = getWishListLink();
ModalPopupExtender modal = (ModalPopupExtender)loginUserControl.FindControl("loginPopUp");
modal.Show();
This will set the urlForRedirecting property before you open the form, meaning you can access it once it's open.
Use ViewState between postbacks otherwise value of property will be lost.
public string UrlForRedirecting
{
get
{
object urlForRedirecting = ViewState["UrlForRedirecting"];
if (urlForRedirecting != null)
{
return urlForRedirecting as string;
}
return string.Empty;
}
set
{
ViewState["UrlForRedirecting"] = value;
}
}
精彩评论