Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Easy question to put a logout button instead of a link.

Posted on 2008-11-19
15
Medium Priority
?
710 Views
Last Modified: 2012-08-13
if you got to omegalove.com
and try
username:mathieu
password:cupryk

U will get a logout linkbutton.
I would like to change this to a button.
<%@ Control Language="C#" AutoEventWireup="true"  CodeFile="Login.ascx.cs" Inherits="Controls_Login" %>
          <link href="../App_Themes/PlainHtml/Default.css" rel="stylesheet"
    type="text/css" />
          <div id="loginbox">
            <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
               <asp:Login ID="Login" runat="server"
                    DestinationPageUrl="~/Profile.aspx" FailureAction="RedirectToLoginPage"
                    Height="31px">
                  <LayoutTemplate>
                   <table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                           <td>
                           <asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:"  />
                           <asp:TextBox id="UserName" runat="server" BorderColor="DarkGray"
                                   BorderStyle="Inset" BorderWidth="2px" />
                           <asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True"
                                 ControlToValidate="UserName" Text="*" ValidationGroup="Login"  />                    
                               <asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password"
                                   Text="Password:" />
                               <asp:TextBox ID="Password" runat="server" TextMode="Password"
                                   BorderColor="DarkGray" BorderStyle="Inset" BorderWidth="2px" />
                               <asp:RequiredFieldValidator ID="valRequirePassword" runat="server"
                                   ControlToValidate="Password" SetFocusOnError="True" Text="*"
                                   ValidationGroup="Login" />
&nbsp;<asp:Button CssClass="blackButton2"  validationgroup="Login" CommandName="Login"
                                        ID="Submit" runat="server" Text="Login" Font-Bold="True" />
                              </td>
                           
                        </tr>
                        <tr>
                            <td>
                                <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me"
                              ForeColor="DarkSlateGray"></asp:CheckBox>&nbsp;|&nbsp;<asp:HyperLink ID="lnkPasswordRecovery" runat="server" NavigateUrl="~/PasswordRecovery.aspx">Forgot
                                password?</asp:HyperLink>
                            </td>
                           
                        </tr>
                     </table>
                  </LayoutTemplate>
               </asp:Login>
            </AnonymousTemplate>
           
            <LoggedInTemplate>
               <div id="welcomebox">
                  <asp:LoginName ID="LoginName1" runat="server" FormatString="Hello      {0}" /><br />
                  <small>
                  <asp:HyperLink ID="lnkProfile" runat="server" Text="Edit Profile" NavigateUrl="~/EditProfile.aspx" /><br />
                  <asp:LoginStatus ID="LoginStatus1" Runat="server" />
                  </small>
               </div>
            </LoggedInTemplate>
         </asp:LoginView>
        </div>

     
     
0
Comment
Question by:mathieu_cupryk
  • 7
  • 5
  • 3
15 Comments
 
LVL 4

Expert Comment

by:lotusnotesnewbie
ID: 23001517
Could you use a button image instead of  a button and change the Login status control like <asp:LoginStatus ID="LoginStatus1" runat="server" LoginImageUrl="~/images/<button image>.gif" />
0
 
LVL 2

Accepted Solution

by:
jacksonm1234 earned 1000 total points
ID: 23006642
Instead of using the LoginStatus control, just put a regular button in its place that says "logout". Set its "visible" property to False.

When the page loads, check to see if the user is logged in by using the "User.Identity.IsAuthenticated" property. If it returns true, then you can set your new button's visible property to true.

In then event handler for your new button, you simply need to put "FormsAuthentication.SignOut()" to manually sign the user out. I'll attach some code so it will make more sense. I hope it helps!
ASPX code:
<asp:LinkButton ID=lnkLogout runat=server Text="Logout" Visible=False></asp:LinkButton>
 
 
Form_Load code.
 
If Not Page.IsPostBack Then
            If User.Identity.IsAuthenticated Then
                lnkLogout.Visible = True
                
            Else
                lnkLogout.Visible = False
                
            End If
        End If
 
Button code. Notice that I used a link button, but a regular button will do.
 
Protected Sub lnkLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLogout.Click
        FormsAuthentication.SignOut()
        
    End Sub

Open in new window

0
 

Author Comment

by:mathieu_cupryk
ID: 23010048
lotus if you try to login to omegalove.com
with mathieu and password cupryk
u will see the button not working well.
<asp:LoginStatus ID="LoginStatus1" Runat="server" CssClass="blackButton2" Font-Bold />
                 
Can you give me a hand.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:jacksonm1234
ID: 23010266
Did you have any questions on my solution? I thought I gave you the answer you were looking for but maybe not...
0
 
LVL 4

Assisted Solution

by:lotusnotesnewbie
lotusnotesnewbie earned 1000 total points
ID: 23010900
Could you add this to your CSS file
A.blackButton2:link {
TEXT-DECORATION: none
}
A.blackButton2:hover {
TEXT-DECORATION: none
}
and remove Font-Bold in your <asp:LoginStatus ID="LoginStatus1" Runat="server" CssClass="blackButton2" Font-Bold /> You are almost there just modify the CSS a little you will get it like the buttons you have below.
Happy Coding!
0
 

Author Comment

by:mathieu_cupryk
ID: 23016693
jack and lotus it is still not working.
Any help would be great
0
 

Author Comment

by:mathieu_cupryk
ID: 23016715
try username accopaper
password omegalove
it is still not the right size I would like to put the font color to white instead of having orange and red.
0
 

Author Comment

by:mathieu_cupryk
ID: 23023606
any answers?
0
 
LVL 2

Expert Comment

by:jacksonm1234
ID: 23025089
Did you try my solution?  
0
 

Author Comment

by:mathieu_cupryk
ID: 23030621
actual I had to use a button.
0
 
LVL 4

Expert Comment

by:lotusnotesnewbie
ID: 23033945
Was just back will look into it and let you know before today
0
 
LVL 4

Expert Comment

by:lotusnotesnewbie
ID: 23035724
let me know if this helps

<asp:LoginStatus ID="LoginStatus1" runat="server" LoginImageUrl="~/images/login.png" LogoutImageUrl="~/images/logout.png"/>  - No CSS required. Just two button like images.
0
 

Author Comment

by:mathieu_cupryk
ID: 23037605
I already implement go to omegalove.com
type username: macupryk
password: cupryk
0
 
LVL 4

Expert Comment

by:lotusnotesnewbie
ID: 23042091
:) pardon me
0
 

Author Comment

by:mathieu_cupryk
ID: 23042684
no worries.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question