Click here to Skip to main content
14,978,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I have a little problem. Once a user logs in they can log out on the welcome page but I but a log out button on the other pages as well and when the user clicks the logout button nothing happens. What did I do wrong or forget? This is the page I put the logout button on that does not work.

C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;

public partial class FinancialProfileFormC : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
        con.Open();

        string insCmd = "Insert into TableFIN (FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP) values (@FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        insertUser.Parameters.AddWithValue("@FINYR", TextBoxCYF.Text);
        insertUser.Parameters.AddWithValue("@TOTSL_REVE", TextBoxTRIR);
        insertUser.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        insertUser.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        insertUser.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        insertUser.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        insertUser.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        insertUser.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        insertUser.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        insertUser.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
        insertUser.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        insertUser.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        insertUser.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        insertUser.Parameters.AddWithValue("@OTHEREXP", TextBoxOE.Text);

        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            Response.Redirect("FinancialIndicatorsForm.aspx");
        }
        catch (Exception er)
        {
            Response.Write("You Have Successfully Submitted the Information!!!");
        }
        finally
        {

        }
    }
    protected void ButtonPrint_Click(object sender, EventArgs e)
    {

    }

    protected void ButtonLogout_Click(object sender, EventArgs e)
    {
        Session["New"] = null;
        Response.Redirect("Login.aspx");
    }
}


Here is the code that does work.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class IALOPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["New"] = null;
        Response.Redirect("Login.aspx");
    }
}
Posted

   
v3
Comments
Computer Wiz99 26-Jun-13 9:47am
   
ASPNET -i,

I tried the method you showed and still no go. Anything else I can try?
bbirajdar 26-Jun-13 9:53am
   
This should work as it works always.. I am thinking why it did not work for you.
Computer Wiz99 26-Jun-13 9:56am
   
Well I am reading the articles you gave me and trying to see what I missed.
bbirajdar 26-Jun-13 9:57am
   
Ok.. Tell me what exact behaviour you are expecting on the click of logout button..
Computer Wiz99 26-Jun-13 10:20am
   
What I am trying to get is when the user is finished filling out the form and clicks submit, they can click on log out to log them out of the session. The logout redirects them back to the log in screen. When I click on the log out on the form page it pops up all of the control validation.
bbirajdar 26-Jun-13 10:39am
   
Thats a proper description of the problem.. 'a no go' or 'does not work' does not make any sense to a third person who is not looking at your screen....

You need to specify the 'validation group' so that the validation will be fired only on the click of submit button and not on logout button

http://msdn.microsoft.com/en-us/library/ms227424(v=vs.100).aspx
Computer Wiz99 26-Jun-13 10:47am
   
Ok. Thanks. Will do.
Try This....:)

C#
protected void ButtonLogout_Click(object sender, EventArgs e)
    {
             

               Session.Abandon();
              Session.Clear();
              Response.Redirect("Login.aspx");

          
       
  }
   
Comments
Computer Wiz99 26-Jun-13 10:47am
   
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900