fill dropdownlist inside login control template

fill a dropdownlist control inside the login control,layout template

Page 1 of 1

3 Replies - 3851 Views - Last Post: 15 January 2011 - 10:42 AM Rate Topic: -----

#1 tinase  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 33
  • Joined: 19-June 08

fill dropdownlist inside login control template

Posted 12 March 2010 - 03:58 AM

:taz: fast help


I am Using Visual Studio 2008 sp1
I dragged a LoginControl from the toolbox,I have the membership database(aspnetdb.mdf)and everthing works fine.

1st I wanted to set destinationpageurl to be set based on the roles.
To set that i wrote the following code in the loggedin event of the login button(works fine too) anyone can advise me if there is a better way of doing it.
<%@ Page Title="" Language="VB" MasterPageFile="~/HomePages.master" %>

<script runat="server">

    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn

        If (Membership.ValidateUser(Login1.UserName, Login1.Password)) Then
            
            For Each role In Roles.GetRolesForUser(Login1.UserName)


                Select Case role

                    Case Is = "Family Member"
                        Response.Redirect("~/Family Member/FamilyMemberHome.aspx")
                    Case Is = "Family Representative"
                        Response.Redirect("~/Family Representative/FamilyRepresentativeHome.aspx")
                    Case Is = "Record Officer"
                        Response.Redirect("~/Record Officer/RecordOfficerHome.aspx")
                    Case Is = "Executive"
                        Response.Redirect("~/Executive/ExecutiveHome.aspx")
                    Case Is = "System Administrator"
                        Response.Redirect("~/System Administrator/SystemAdministratorHome.aspx")
                    Case Is = "Information Officer"
                        Response.Redirect("~/Information Officer/InformationOfficerHome.aspx")

                End Select

            Next
        End If
  End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
    <asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" 
        BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" 
        Font-Size="0.8em" ForeColor="#333333" Height="179px" Width="455px">
        <TextBoxStyle Font-Size="0.8em" />
        <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" 
            BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
        <LayoutTemplate>
            <table border="0" cellpadding="4" cellspacing="0" 
                style="border-collapse:collapse;">
                <tr>
                    <td>
                        <table border="0" cellpadding="0" style="height:179px;width:455px;">
                            <tr>
                                <td align="center" colspan="2" 
                                    style="color:White;background-color:#5D7B9D;font-size:0.9em;font-weight:bold;">
                                    Log In</td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="UserName" runat="server" Font-Size="0.8em" Width="162px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                        ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                        ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="Password" runat="server" Font-Size="0.8em" TextMode="Password" 
                                        Width="163px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                        ControlToValidate="Password" ErrorMessage="Password is required." 
                                        ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color:Red;">
                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="LoginButton" runat="server" BackColor="#FFFBFF" 
                                        BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Login" 
                                        Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" Text="Log In" 
                                        ValidationGroup="Login1" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
        <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" 
            ForeColor="White" />
    </asp:Login>
</asp:Content>





2nd thing I wanted to do is what

my question actually is.
I wanted the users to select their role form a dropdownlist and log in based on roles. I am doing this because in the website i am developing, one user may have more than one role. For instance a Family Representative may log in as a role Family Representative or as a role Family Member
My Attempt to do this is as follows
1. I converted the lo-gin control into a template
2. I inserted a dropdownlist control and a LinkButton.When The LinkButton is clicked after the username is filled it is supposed fill up the dropdownlist with the roles that the user is involved
3. I created the following subroutine in order to fill the dropdownlist
Public Sub FillRoles()
Dim role As String
        DropDownList1.Items.Clear()
        DropDownList1.Items.Add("Choose your role")
        For Each role In Roles.GetRolesForUser(Login1.UserName)
            DropDownList1.Items.Add(role)
        Next

        If (DropDownList1.Items.Count = 1) Then
            DropDownList1.Items.Clear()
            roleStatus.Text = "You are not assigned to any role"
        Else
            roleStatus.Text = ""
        End If
End Sub



4. Here are the problems i encountered
I cant make an event handling when the linkbutton is clicked(the click event handler of the linkbutton i.e linkbutton1.click)
I wanted to call fillRoles when the linkbutton is clicked

I think the problem occurs because my own controls i inserted(the linkbutton and dropdownlist) are inside the"<LayoutTemplate>"
"</LayoutTemplate> "
How can i resolve this issue?

This post has been edited by tinase: 12 March 2010 - 04:11 AM


Is This A Good Question/Topic? 3
  • +

Replies To: fill dropdownlist inside login control template

#2 suckedforu  Icon User is offline

  • New D.I.C Head

Reputation: -13
  • View blog
  • Posts: 8
  • Joined: 15-January 11

Re: fill dropdownlist inside login control template

Posted 15 January 2011 - 09:57 AM

This is very long
NOBODY!!! Replied
Was This Post Helpful? -4
  • +
  • -

#3 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: fill dropdownlist inside login control template

Posted 15 January 2011 - 10:15 AM

Oh looky, more + rep abuse from the same IP address. Would be a shame if I have to ban all of you. STOP IT
Was This Post Helpful? 0
  • +
  • -

#4 suckedforu  Icon User is offline

  • New D.I.C Head

Reputation: -13
  • View blog
  • Posts: 8
  • Joined: 15-January 11

Re: fill dropdownlist inside login control template

Posted 15 January 2011 - 10:42 AM

View Postskyhawk133, on 15 January 2011 - 10:15 AM, said:

Oh looky, more + rep abuse from the same IP address. Would be a shame if I have to ban all of you. STOP IT


This is a computer used by many people @t our office

and we are all friends using dreamincode
of course tinase and geme123 are my friends
and all of us here including geme123,javaxedforu are trying to make the reputation of our
friend tinase positive.

I KNOW YOU KNOW IT ALL OF THIS IS A LIE AND A LIE AND A LIE
ALL THOSE ACCOUNTS ARE DUPLICATED BY ME
SO I WILL STOP THIS.STARTING FROM NOW...
I AM tinase myself, trying to make my reputation positive
CAN YOU REMOVE my ban(tinase's ban) please please ......
//please remove tinase's ban now please 


Was This Post Helpful? -6
  • +
  • -

Page 1 of 1