Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My task is to create .ASCX control for registration and login and then call this in site.master. And at the same time, want these forms to be appeared as modal pop up. When i click on login then login pop up should appear and the same for registration.If i put <uc:Login ID="ucLogin" runat="server" /> code first then Login works and registration does not and the vice-versa. I think the problem is here:

<uc:Login ID="ucLogin" runat="server" /> 
<uc1:Registration ID="Registration" runat="server"  />


I do not know whether it is good to put
<uc1:Registration ID="Registration" runat="server"/> under  <asp:LoginView runat="server" ViewStateMode="Disabled">
The whole site.Master page looks like this:

What I have tried:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

    <%@ Register Src = "~/Controls/Login.ascx" TagName = "Login" TagPrefix = "uc" %>
    <%@ Register Src="~/Controls/Registration.ascx" TagPrefix="uc1" TagName="Registration" %>

    <!DOCTYPE html>

    <html lang="en">
    <head runat="server">

        <asp:PlaceHolder runat="server">

        </asp:PlaceHolder>

    </head>
    <body>
        <form runat="server">
            <asp:ScriptManager runat="server">

            </asp:ScriptManager>

                        <asp:LoginView runat="server" ViewStateMode="Disabled">
                            <AnonymousTemplate>
                                <ul class="nav navbar-nav navbar-right">

                                    <li>  <uc:Login ID="ucLogin" runat="server" />     </li>
                                    <li> <uc1:Registration ID="Registration" runat="server"  /></li>
                                </ul>

                            </AnonymousTemplate>
                          </asp:LoginView>  

                    </div>
                </div>
            </div>
            <div class="container body-content">
                <asp:ContentPlaceHolder ID="MainContent" runat="server">
                </asp:ContentPlaceHolder>
                <hr />

            </div>
        </form>
    </body>
    </html>



And the Login.ascx is:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Login.ascx.cs" Inherits="Login" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:LinkButton ID="lnkLogin" runat="server" Text="Login"></asp:LinkButton>
<asp:Panel ID="pnlLogin" runat="server" CssClass="modalPopup" Style="display: none">


    <div class="form-group">
        <asp:Label runat="server" AssociatedControlID="Email" CssClass="col-md-3 control-label">User name</asp:Label>
        <div class="col-md-9">
            <asp:TextBox runat="server" ID="Email" CssClass="form-control" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
                CssClass="text-danger" ErrorMessage="The user name field is required." />
        </div>
    </div>
    <div class="form-group">
        <asp:Label runat="server" AssociatedControlID="Password" CssClass="col-md-3 control-label">Password</asp:Label>
        <div class="col-md-9">
            <asp:TextBox runat="server" ID="Password" TextMode="Password" CssClass="form-control" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="Password" />
        </div>
    </div>

    <div class="form-group">

        <asp:Button runat="server" OnClick="LogIn" Text="Log in" CssClass="btn btn-default" />
    </div>

</asp:Panel>
<cc1:ModalPopupExtender ID="popup" runat="server" DropShadow="false"
    TargetControlID="lnkLogin" PopupControlID="pnlLogin"
    BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>


The registration.ascx page looks like this:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Registration.ascx.cs" Inherits="Registration" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc11" %>

<asp:LinkButton ID="lnkRegistration" runat="server" Text="Registration"></asp:LinkButton>
<asp:Panel ID="pnlRegistration" runat="server">

    <div class="form-group">
        <asp:Label runat="server" AssociatedControlID="EmailId" CssClass="col-md-2 control-label">Email Address</asp:Label>
        <div class="col-md-10">
            <asp:TextBox runat="server" ID="EmailId" CssClass="form-control" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="EmailId" />
        </div>
    </div>
    <div class="form-group">
        <asp:Label runat="server" AssociatedControlID="Password" CssClass="col-md-2 control-label">Password</asp:Label>
        <div class="col-md-10">
            <asp:TextBox runat="server" ID="Password" TextMode="Password" CssClass="form-control" />
            <asp:RequiredFieldValidator runat="server" ControlToValidate="Password" />
        </div>
    </div>

    <div class="form-group">
        <asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" CssClass="btn btn-default" />
    </div>

</asp:Panel>

<cc11:ModalPopupExtender ID="popup1" runat="server" DropShadow="false"
    TargetControlID="lnkRegistration" PopupControlID="pnlRegistration"
    BackgroundCssClass="modalBackground" CancelControlID="lnkCancel">
</cc11:ModalPopupExtender>
Posted
Updated 22-May-23 1:51am
v4
Comments
Richard Deeming 10-Oct-17 11:20am    
We can't see the registration link, nor the script that's supposed to fire when you click it.

Click "Improve question" and add the relevant parts of your code. Include the full details of any errors logged in the browser's error console, and remember to indicate which line of code they relate to.
Rajeshyadav12 10-Oct-17 16:29pm    
@richard deeming, I have made changes in the questions and included both registration and login user control. Please have a look. Thank you in advance.

1 solution

If my guess is correct on what you want to achieve then I would suggest you to change your approach.

1. If you are registering your ascx controls to master page I am not sure how you would display them as popup.

Instead you should have two different aspx pages and register logo and register control to different pages. You can open these aspx pages as popup from the links.

You can use single aspx page to register both ascx controls and hide one based on which link you are clicking. However, this violate the single responsibility principle.

Hope this helps..
 
Share this answer
 
Comments
Rajeshyadav12 10-Oct-17 22:05pm    
@AtlapureAmbrish, My concern is that I have two links Login and Registration. But Only one link is working. I can not see any error in console. Nothing is happening.What i want is, if i click on login then login popup should appear and same for registration. Please guide me. I can not understand why only one link is working from <uc:Login ID="ucLogin" runat="server" />
<uc1:Registration ID="Registration" runat="server" />
Atlapure Ambrish 11-Oct-17 3:09am    
what do you mean by link? have you added any hyperlink in your code? I don't see any. Please provide more details.
Rajeshyadav12 11-Oct-17 16:21pm    
@AtlapureAmbrish, Can you please see the link button on login.ascx and registration.ascx page? <asp:LinkButton ID="lnkRegistration" runat="server" Text="Registration"> and <asp:LinkButton ID="lnkLogin" runat="server" Text="Login">.

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



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