views:

10921

answers:

2

Dear All,

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

+2  A: 

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")); });

nunespascal
+5  A: 

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.

Gromer
SO inside the codebehind file i will check for the authentication and if the user is valid,redirect to another page ,Else show a messgae in the same same modal popup. How can i communicate back to my javascrip from the C#.net code ?
Shyju
From what I understood in your original question, this check would be in your code behind for PriceList.aspx. You would check if the user was authenticated and then register that in the hidden field. That is how you communicate it with the javascript.ClientScript.RegisterHiddenField("isAuthenticated", "false");That renders something like this in the page:<input type="hidden" id="isAuthenticated" value="false" />
Gromer
Thanks Grommer.But i am having a problem with this code.I posted it here.http://stackoverflow.com/questions/876295/asp-net-with-jqueryui-server-side-event-not-firing can u please have a look at it and advice me
Shyju