Solved

ASP Error effecting javascript function

Posted on 2013-10-29
5
482 Views
Last Modified: 2013-11-08
My asp.net c# site currently has a login area on it.  Anytime some puts in the wrong username or password, it effects the javascript function (onclick method) which makes the page all black with an opacity and prompts a box for a password reminder.  If you click on the link when you first go there, it works.  After putting in the wrong username or password, it will throw an error text and then the javascript link stops working.

.aspx
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="test.master.cs" Inherits="testing.Site" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html>

<html lang="en">
  <head id="Head1" runat="server">
    <meta content="text" charset="utf-8">
    <title>National Roofing Industry Pension Plan</title>
          <asp:ContentPlaceHolder id="head" runat="server">

    </asp:ContentPlaceHolder>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
<link rel='stylesheet' href="css/tooltips.css">
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>


<script type="text/javascript">
    $(document).ready(function () {
        $('a.login-window').click(function () {

            // Getting the variable's value from a link 
            var loginBox = $(this).attr('href');

            //Fade in the Popup and add close button
            $(loginBox).fadeIn(300);

            //Set the center alignment padding + border
            var popMargTop = ($(loginBox).height() + 24) / 2;
            var popMargLeft = ($(loginBox).width() + 24) / 2;

            $(loginBox).css({
                'margin-top': -popMargTop,
                'margin-left': -popMargLeft
            });

            // Add the mask to body
            $('body').append('<div id="mask"></div>');
            $('#mask').fadeIn(300);

            return false;
        });

        // When clicking on the button close or the mask layer the popup closed
        $('a.close, #mask').live('click', function () {
            $('#mask , .login-popup').fadeOut(300, function () {
                $('#mask').remove();
            });
            return false;
        });
    });
</script>




  </head>

  <body onLoad="goforit()">
   
          <form id="fi_NRIPF" runat="server" autocomplete="off">
              <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>


                    <asp:UpdatePanel ID="up_MainPanel" runat="server" UpdateMode="Conditional">
          <ContentTemplate>
                              <asp:UpdateProgress ID="up_MainThrobber" runat="server" AssociatedUpdatePanelID="up_MainPanel" DisplayAfter="1000">
  <ProgressTemplate>
    <div id="processingBackground" align="center">
    <div id="processingMessage">
          <div align="center" style="margin:400px;"><strong>PROCESSING...</strong><br />
              <br />
          <asp:Image ID="img_ThrobberHistory" runat="server" ImageUrl="~/images/throbber.gif" Width="100px" Height="100px" /></div>
          <br />&nbsp;<br />

    </div></div>
  </ProgressTemplate>
</asp:UpdateProgress>


  <div id="container">

                            <div class="navbar">        
                                 <div class="navbar-inner">
                                     <table width="100%" border="0" style="height:100px;">
  <tr>
    <td>
  
        <%--<img src="Images/union_logo.png" style="max-width:90%;float:left;padding-bottom:10px;" />--%></td>
            <td>
<%--                <table border="1" width="100%">
                    <tr><td><hr style="color:#cd6b2e;background-color:#cd6b2e;height:1px;border:0;"/></td><td>&nbsp;</td></tr>
                    <tr><td colspan="2"><strong><p>NRIPP</p></strong></td></tr>
                    <tr><td colspan="2"><p>National Roofing Industry</p></td></tr>
                    <tr><td colspan="2"><p>Pension Plan</p></td></tr>
                    <tr valign="top"><td width="80%"><hr style="color:#cd6b2e;background-color:#cd6b2e;height:10px;border:0;"/></td><td>&nbsp;</td></tr>
                </table>--%>
             </td>     
    <td align="right">
<asp:Login ID="log_Master" runat="server" BorderColor="#E6E2D8" BorderPadding="0" BorderStyle="Solid" BorderWidth="0px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" CssClass="loginarea" VisibleWhenLoggedIn="False" DestinationPageUrl="dashboard.aspx" OnAuthenticate="Login1_Authenticate"  Height="181px" DisplayRememberMe="False">
                                        <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
                                       
                                         <LayoutTemplate>
        <table width="100%" height="120px"  border="0" >
  <tr>
    <td valign="top" align="right"><asp:Label ID="lb_UserName" runat="server" AssociatedControlID="UserName" ForeColor="#ffffff">Email:</asp:Label></td>
    <td><asp:TextBox ID="UserName" runat="server" Font-Size="1.5em" ValidationGroup="vg_Login" CssClass="formtextbox"></asp:TextBox>
        <asp:TextBoxWatermarkExtender ID="wm_UserName" runat="server" WatermarkCssClass="watermark" TargetControlID="UserName" WatermarkText="e-mail@domain.com"></asp:TextBoxWatermarkExtender>
        <asp:RegularExpressionValidator ID="rev_Email" runat="server" ErrorMessage="<br />Invalid Email Address." ForeColor="#ffffff" ControlToValidate="UserName" Font-Size="Small" ValidationGroup="vg_Login" ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" Display="Dynamic"></asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="rfv_Email2" runat="server" ControlToValidate="UserName" Font-Size="small" ErrorMessage="<br/>Email Address is required." ForeColor="#ffffff" ValidationGroup="vg_Login" Display="Dynamic"></asp:RequiredFieldValidator></td>
      </tr>
  <tr>
    <td valign="top" align="right"><asp:Label ID="lb_Password" runat="server" AssociatedControlID="Password" ForeColor="#ffffff">Password:</asp:Label></td>
    <td><asp:TextBox ID="Password" runat="server" Font-Size="1.5em" TextMode="Password" ValidationGroup="vg_Login" CssClass="formtextbox"></asp:TextBox>
       <%-- <asp:TextBoxWatermarkExtender ID="wm_Password" runat="server" WatermarkCssClass="watermak" TargetControlID="Password" WatermarkText="ie. - 123456789 or Doe, John" ViewStateMode="Inherit" Enabled="True"></asp:TextBoxWatermarkExtender>
        --%>    </td><td>            
		</td>
  </tr>
  <tr>
    <td colspan="3">
	<asp:RequiredFieldValidator ID="rfv_Password2" runat="server" ControlToValidate="Password" Font-Size="small" ErrorMessage="Password is Required.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ForeColor="#ffffff" ValidationGroup="ctl00$Login1"></asp:RequiredFieldValidator>	</td>
  </tr>
  <tr>
    <td colspan="3"><asp:Label ID="lb_loginError" runat="server" ForeColor="White"></asp:Label></td>
  </tr>
  <tr>
    <td>
        <asp:LinkButton ID="lkbtn_forgot" runat="server" href="#login-box" class="login-window" PostBackUrl="~/Default.aspx" style="color:#fff;">Forgot your password?</asp:LinkButton>
        
    </td>
    <td align="right" ><asp:Button ID="btn_Login" runat="server" CommandName="Login" Text="Log In" align="right" ValidationGroup="vg_Login"  CssClass="mainbutton-style" /></td>
   

                                         <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
                                     
        </tr>
                                         </table>
                                           </LayoutTemplate>
    </asp:Login>
        </td>
          <td>
             <table style="float:right;" border="0" height="200px">
                                        <tr><td colspan="2">&nbsp;</td></tr>
                                          <tr align="left"><td><asp:LoginName ID="lin_MasterUserName" runat="server" ForeColor="White" Font-Bold="true" />&nbsp;&nbsp;</td></tr>
                                         <tr><td align="center">
                                         <asp:LoginStatus ID="lis_MasterUserStatus" runat="server" LoginText="" LogoutPageUrl="~/Default.aspx" ForeColor="White" LogoutAction="Redirect" LogoutImageUrl="~/images/logout.png" /></td></tr>
                                         </table>   

</td>
  </tr>
</table>
          
</div>

Open in new window


C#
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string userName = log_Master.UserName;
            string password = log_Master.Password;
            e.Authenticated = Membership.ValidateUser(log_Master.UserName, log_Master.Password);
            {
                if (Membership.ValidateUser(log_Master.UserName, log_Master.Password))
                {
                    try
                    {
                        ds_UserKey.SelectParameters["UserName"].DefaultValue = log_Master.UserName;
                        SqlDataReader Reader = (SqlDataReader)ds_UserKey.Select(DataSourceSelectArguments.Empty);
                        Reader.Read();
                        Session["userName"] = log_Master.UserName.ToString();
                        
                    }
                    catch
                    {
                        Label lb_loginError = (Label)log_Master.FindControl("lb_loginError");
                        lb_loginError.Text = "The Email or Password you provided is invalid.";
                        lb_loginError.ForeColor = System.Drawing.Color.Red;
                        
                    }
                }
                else
                {
                    Label lb_loginError = (Label)log_Master.FindControl("lb_loginError");
                    lb_loginError.Text = "The Email or Password you provided is invalid.";
                    lb_loginError.ForeColor = System.Drawing.Color.Red;
                    init();
                }
                {
                }
                
            }
        }

    }

Open in new window

0
Comment
Question by:Shade22
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
Hi,

Why are you returning false in each of your javascript events?

What is the error you're getting?

Do you have a link to the page?

Cheers,

Rob
0
 
LVL 14

Accepted Solution

by:
dejaanbu earned 500 total points
Comment Utility
i guess that's because of updatepanel.

use ajax's  pageLoad() instead of document.ready...

function pageLoad(){
//move all your js code here and remove $(document).ready(function () {
//}); block
}

Open in new window


more details here
0
 

Author Comment

by:Shade22
Comment Utility
so this is my javascript now, but it still does not work.

<script type="text/javascript">
    function pageLoad(){
  
        $('a.login-window').click(function () {

            // Getting the variable's value from a link 
            var loginBox = $(this).attr('href');

            //Fade in the Popup and add close button
            $(loginBox).fadeIn(300);

            //Set the center alignment padding + border
            var popMargTop = ($(loginBox).height() + 24) / 2;
            var popMargLeft = ($(loginBox).width() + 24) / 2;

            $(loginBox).css({
                'margin-top': -popMargTop,
                'margin-left': -popMargLeft
            });

            // Add the mask to body
            $('body').append('<div id="mask"></div>');
            $('#mask').fadeIn(300);

            return false;
        }); block

        // When clicking on the button close or the mask layer the popup closed
        $('a.close, #mask').live('click', function () {
            $('#mask , .login-popup').fadeOut(300, function () {
                $('#mask').remove();
            });
            return false;
        });
    });
   
</script>

Open in new window

0
 

Author Closing Comment

by:Shade22
Comment Utility
Thanks! I have been working on this issue for quite some time.  I moved the hyperlink outside the update panel and it worked like it should.  Is it possible to get it to work inside the update panel?
0
 
LVL 14

Expert Comment

by:dejaanbu
Comment Utility
i couldnt able to see any hyperlink in your code...just check by setting hyperlink's clientidmode to "static"
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now