Adding a Password Pop-Up dialog (using javascript?)

Last post 05-15-2008 11:50 AM by gte351s. 5 replies.

Sort Posts:

  • Adding a Password Pop-Up dialog (using javascript?)

    05-11-2008, 2:28 AM
    • Loading...
    • gte351s
    • Joined on 12-13-2007, 12:02 PM
    • Posts 103

    Hi - I'd like to add a password dialog box to my page. This will be used to confirm delete on records from a DB. I don't really know where to start, but I have an idea of what I'd like it to look like -- a good example is the master password dialog in firefox: in FF, go to Tools > Options... > Security Tab > Show Passwords (if you've set a master password). Basically, this should be a simple pop-up that'll contain a text field, an OK and Cancel buttons. I'd like to then be able to then get the user input back so I could make the validation.

    Thanks! 

  • Re: Adding a Password Pop-Up dialog (using javascript?)

    05-11-2008, 7:09 AM
    • Loading...
    • anzer
    • Joined on 10-19-2004, 4:00 AM
    • UAE
    • Posts 824

    I couldn't actually understand your question.

    If you are looking for a confirmation box for some user action, following sample code may be helpful to you.

            <asp:Button OnClientClick="return confirm('Are you sure you want to do this operation?');"  runat="server" ID="btnTest" OnClick="btnTest_Click" />

     
    Here in the OnClientClick of a button am showing a confirmation pop up, if the user click Yes it will execute the server side code, otherwise the form will not post to server.

    If this post was useful to you, please mark it as answer.

    My Blog | Free books Microsoft
  • Re: Adding a Password Pop-Up dialog (using javascript?)

    05-12-2008, 4:17 AM
    • Loading...
    • gte351s
    • Joined on 12-13-2007, 12:02 PM
    • Posts 103

    The above is already implemented in my code. I wanted to take it up a notch and present a password pop-up dialog, where the user will have to enter a password to confirm an action. Any ideas how? Thanks.
     

  • Re: Adding a Password Pop-Up dialog (using javascript?)

    05-12-2008, 6:19 AM
    • Loading...
    • gte351s
    • Joined on 12-13-2007, 12:02 PM
    • Posts 103

     I found that using this simple javascript code will get a password box working:

     

    confirm("Please enter your password:", "");
     

    It then returns a password as a string. I'm just not sure how to:

    a) Mask the input as * (so that you'll see "***" instead of "123")

    b) Get the user input so I could use it

    Any help will rock.
     

  • Re: Adding a Password Pop-Up dialog (using javascript?)

    05-12-2008, 7:28 AM
    Answer
    • Loading...
    • anzer
    • Joined on 10-19-2004, 4:00 AM
    • UAE
    • Posts 824

    You can assign the value from prompt to some hiddenfield and use it on the server side.

    HTML Code

     <script language="javascript" type="text/javascript">
        function getPassword()
        {
            var pwd = prompt('Please enter your password:', '');
            
            if(pwd != null)
            {
                if(pwd != '')
                {
                    document.getElementById('hidPassword').value = pwd;
                    return true;
                }
            }
            
            return false;
        }
        </script>

    <asp:Button ID="Button2" runat="server" Text="Button2_Click" OnClientClick="return getPassword()" OnClick="Button2_Click1"/>
    <asp:HiddenField ID="hidPassword" Value="" runat="server" />

    Server side code 

     protected void Button2_Click1(object sender, EventArgs e)
        {
            Response.Write(hidPassword.Value);
        }

     

     There is no inbuilt masking capability for prompt in javascript. If you want to do anything like that, you need to create custom model popups.

    There are lot of free code availble to create custom odel popups. Here are some sample links

    http://javascript.about.com/library/blmodald1.htm

    http://www.orangoo.com/labs/GreyBox/

    http://jquery.com/demo/thickbox/

    In thease popups you can show what ever html you want. So crate another HTML page with a password textbox, show it in the popup, get the value........ 

    If this post was useful to you, please mark it as answer.

    My Blog | Free books Microsoft
  • Re: Adding a Password Pop-Up dialog (using javascript?)

    05-15-2008, 11:50 AM
    • Loading...
    • gte351s
    • Joined on 12-13-2007, 12:02 PM
    • Posts 103

     After much debate I decided to implement full password access to my site (I was being lazy at first). Getting various access levels allowed me to achieve exactly what I needed as far as user permissions go in database access. Thanks for your help!

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter