Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

LoginView button issue

Posted on 2009-04-30
4
Medium Priority
?
507 Views
Last Modified: 2012-06-27
I'm using a login view control that will show a button if the users role is "admin".   This button has an onClick event in the code behind page.

If the user is NOT and admin the button doesn't load.  That's how I want it to function.  Admins get the button, users do not.

Here's my problem.

If a user who is not an admin visits the page the page throws a Compilation error that points to the onClick event.  I guessing it's trying to tell me that there is no button associated with this event.

How do I fix this?

0
Comment
Question by:cdemott33
  • 3
4 Comments
 

Author Comment

by:cdemott33
ID: 24270059
Here's my code, if you need it.
<!-- CODE FOUND IN USER CONTROL -->
 
    <asp:LoginView ID="LoginView1" runat="server">
        <RoleGroups>
            <asp:RoleGroup Roles="administrator">
            <ContentTemplate>
                <div id="userControls">
                   <asp:LinkButton ID="btnLogout" runat="server">Logout</asp:LinkButton>  
                </div>
            </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
    </asp:LoginView>
 
<!-- MY USER CONTROL CODE BEHIND BUTTON CLICK EVENT -->
 
Imports System.Web.Security
 
Partial Class pm_header
    Inherits System.Web.UI.UserControl
 
    Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogout.Click
        Session.Abandon()
        Session.Contents.RemoveAll()
        FormsAuthentication.SignOut()
        Response.Cookies.Remove(FormsAuthentication.FormsCookieName)
        FormsAuthentication.RedirectToLoginPage()
    End Sub
End Class

Open in new window

0
 

Author Comment

by:cdemott33
ID: 24270097
And this is the Compliler Error.  FYI: Line 6 below is highlighted in red.

Compiler Error Message: BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Source Error:

 

Line 4:      Inherits System.Web.UI.UserControl
Line 5:  
Line 6:      Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogout.Click
Line 7:          Session.Abandon()
Line 8:          Session.Contents.RemoveAll()
 
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 2000 total points
ID: 24270261
more easy, remove the "Handles btnLogout.Click" and add onclick="btnLogout_Click" to btnLogout (in the aspx page)  
0
 

Author Closing Comment

by:cdemott33
ID: 31576428
That worked perfectly!  Thank you davrob60
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 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