Hello friends,
I have been trying to redirect username and user email from the Login page to Page2.
This is what the Login page looks like and it works.
function register(connect) {
$("#Start").click(function () {
var name = $("#userName").val();
var email = $('#userEmail').val();
if (name.length > 0 && email.length > 0) {
window.location.href = "Page2.aspx";
}
else {
alert("Enter username or password details");
}
});
}
Then in code behind of the Login page I added this:
protected void Start_Click(object sender, EventArgs e)
{
string name = userName.ToString();
Session["Name"] = name.ToString();
}
In Page2 code behind I added this code but the useName and userEmail don’t show up. I added Alert box to test if the username gets redirected but no luck. What am I doing wrong?
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
if (Session["Name"] != null)
{
Label1.Text = Session["Name"].ToString();
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Label1.Text.ToString() + "');", true);
}
}
else
{
FormsAuthentication.RedirectToLoginPage();
}
}