Adding 'onClientClick' javascript to an ASP.NET Login control - Stack Overflow

I've got to put a login page from a 3rd party website in an iframe on another website that I'

I've got to put a login page from a 3rd party website in an iframe on another website that I'm developing. I need to add some JavaScript to break out of the iframe when the user logs in, but I can't make the login button to execute the JavaScript and do the postback for the login - just one or the other.

Here's the code from the iframe'd login page that I'm triying to adapt:

<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
    <asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
        <LayoutTemplate>
                <asp:Label ID="lblUsername" runat="server" AssociatedControlID="Username" Text="Email" />
                <asp:TextBox ID="Username" runat="server" Text="myName" />
                <asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password" Text="Password" />
                <asp:TextBox ID="Password" runat="server" Text="myPassword" />
                <asp:ImageButton ID="btnLogin" runat="server" CommandName="Login" ImageUrl="~/Images/login-submit.gif" AlternateText="Login" OnClientClick="top.location.href = document.location.href; return true;" />
        </LayoutTemplate>
    </asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
    You are currently logged in blurb..
</LoggedInTemplate>

Currently when the login button is clicked, the login page breaks out of the iframe, but then I have to click the button again to log the user in. Can anyone see what I'm doing wrong? Thanks.

I've got to put a login page from a 3rd party website in an iframe on another website that I'm developing. I need to add some JavaScript to break out of the iframe when the user logs in, but I can't make the login button to execute the JavaScript and do the postback for the login - just one or the other.

Here's the code from the iframe'd login page that I'm triying to adapt:

<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
    <asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
        <LayoutTemplate>
                <asp:Label ID="lblUsername" runat="server" AssociatedControlID="Username" Text="Email" />
                <asp:TextBox ID="Username" runat="server" Text="myName" />
                <asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password" Text="Password" />
                <asp:TextBox ID="Password" runat="server" Text="myPassword" />
                <asp:ImageButton ID="btnLogin" runat="server" CommandName="Login" ImageUrl="~/Images/login-submit.gif" AlternateText="Login" OnClientClick="top.location.href = document.location.href; return true;" />
        </LayoutTemplate>
    </asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
    You are currently logged in blurb..
</LoggedInTemplate>

Currently when the login button is clicked, the login page breaks out of the iframe, but then I have to click the button again to log the user in. Can anyone see what I'm doing wrong? Thanks.

Share Improve this question edited Mar 31, 2009 at 14:25 Nick asked Mar 31, 2009 at 14:04 NickNick 5,69610 gold badges55 silver badges73 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

top.location.href is setting the url of the browser to be a new url so you are never pleting the action of the click.

What you could do is set the target of the form to be "_top"

something like

OnClientClick="document.getElementById('MYFORM_CLIENTID').target='_top';return true;"

Looking at your code I think that on the first click you are not logging in. You are just redirecting the parent window to your login page (the one which is displayed in the IFrame at first). That is why you need to click that button twice to log in - on the second time there is no redirect, as the parent window's URL does not change, so basically on the second time the top.location.href = document.location.href part does not yield any results and the login proceeds.

I think that the right course of action would be to authenticate first, then redirect, the opposite of how it looks currently. You can add a script on postback on that page, so that it checks if it's running in a frame and if so, it redirects the parent window to another page. Of course if you can modify the code... With the amount of detail that was provided I'm only able to tell what may be wrong and suggest a fix, but can't give a solution.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744659653a4586384.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信