jQuery Login modal popup for ASP.NET 2.o Page

匆匆过客 提交于 2019-12-03 06:25:35

问题


I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have a login feature in my Home page.So when a user logged in the site, They can go to the pricelist.aspx page easily using a link in homepage.If some one is entering the page with out logging in , I want to show a modal login box (background disabled) to login . I saw this in jqueryui site.Can any one tell me how to impement this in my site ? Is there any security problem in this since i am using the javascript to send the user credentials to the site when using this method (I am not sure) . Please advice. Thanks in advance


回答1:


jQuery Modal Form Dialog is your way to go here. I made a test app doing what you wanted with it and it worked well.

Markup for your ASPX page:

<div id="dialog" title="Please Login">
        <asp:Login ID="login" runat="server" />
</div>

Javascript needed for the page:

$(document).ready(function() {
$("#dialog").dialog({
    bgiframe: true,
    autoOpen: false,
    height: 300,
    modal: true,
    buttons: {
        Cancel: function() {
            $(this).dialog("close");
        }
    },
    close: function() {
        allFields.val("").removeClass("ui-state-error");
    }
});

var isAuthenticated = $("#isAuthenticated").val();
if (isAuthenticated && isAuthenticated == "false") {
    // Display the modal dialog.
    $("#dialog").dialog("open");
}});

Code behind I used on the aspx page:

ClientScript.RegisterHiddenField("isAuthenticated", "false");

You would give it true or false, depending on if the user was authenticated, so the javascript would know to display the login or not.

Now about the security. The login wouldn't be done by the javascript because the user would hit the button on that login page and it would post back to the server like normal. If you wanted to use ajax, you would have to check out the jQuery $.ajax method.




回答2:


Use a jquery dialog:

http://jqueryui.com/demos/dialog

This needs you to add the modal back to the DOM too.

jQuery(".loginPanel").each(function() 
{ 
   var popup = jQuery(this); 
   popup.parent().appendTo(jQuery("form:first")); 
});


来源:https://stackoverflow.com/questions/867109/jquery-login-modal-popup-for-asp-net-2-o-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!