How to show confirmation box at page load ?

4 posts, 0 answers
  1. Bibhudutta
    Bibhudutta avatar
    16 posts
    Member since:
    Jan 2012

    Posted 10 Apr 2013 Link to this post

    Hi,

    I have a login page, in which if the user enters an username which has been already been used by somebody else to login in the application, then i want to show a confirmation message. The confirmation message has to be shown only if the user provides a valid credentials and that username is already been used for another session.
    I have already written down the code for this in the code behind, but I am unable to show a confirmation box at page load. I have tried with the Page.ClientScript.RegisterClientScriptBlock() and Page.ClientScript.RegisterStartupScript() but its not working. This is my aspx page's code :

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="ERPx.Web.Login" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title>BluWare</title>
        <style type="text/css">
            *
            {
                margin: 0;
                padding: 0;
            }
            body
            {
                font-family: Calibri, Verdana, Helvetica, sans-serif;
                background: url(images/login-page-bg.jpg) top center no-repeat #c4c4c4;
                color: #3a3a3a;
            }
            .clear
            {
                clear: both;
            }
            form
            {
                width: 406px;
                margin: 170px auto 0;
            }
            fieldset
            {
                border: 0;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="CheckBoxes, RadioButtons, Buttons, Textbox, Textarea, Fieldset, Label, Select, Zone, GridFormDetailsViews" />
        <telerik:RadWindowManager ID="rwmMain" runat="server" />
        <div>
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%">
                <asp:Panel ID="pnlLogin" runat="server" DefaultButton="btnLogin">
                    <asp:Image runat="server" ID="CompanyLogo" ImageUrl="~/Images/GenericLogo.png" Height="55px"
                        Style="position: absolute; top: 25px" />
                    <table width="406px" cellspacing="10px">
                        <tr>
                            <td>
                                Email Address
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtEmailAddress" runat="server" Width="260px" MaxLength="50" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Password
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtPassword" TextMode="Password" runat="server" Width="260px"
                                    MaxLength="50" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                  
                            </td>
                            <td>
                                <asp:CheckBox ID="chkRememberMe" Text="Remember Me?" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <a href="RequestLogin.aspx">Request Login</a>
                            </td>
                            <td align="right">
                                <asp:Button ID="btnLogin" runat="server" Text="Login  " Width="75px" OnClick="btnLogin_Click" />
                            </td>
                        </tr>
                        <tr align="center">
                            <td colspan="2">
                                <asp:Label ID="lblError" ForeColor="Red" runat="server" Text="Invalid login. Please try again."
                                    Visible="false" />
                            </td>
                        </tr>
                    </table>
                    <br />
                    <br />
                    <br />
                    BluWare  <asp:Label ID="lblSoftwareVersion" runat="server" />
                </asp:Panel>
            </telerik:RadAjaxPanel>
        </div>
        </form>
    </body>
    </html>

    protected void Page_Load(object sender, EventArgs e)
            {
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Session.Abandon();
                FormsAuthentication.SignOut();
      
                if (IsPostBack)
                {
                    if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())))
                    {
                        txtPassword.Attributes["value"] = txtPassword.Text;
                    }
                }
            }
      
            protected void btnLogin_Click(object sender, EventArgs e)
            {
                Users usr = new Users();
                DataTable dt = usr.ValidateUser(txtEmailAddress.Text, Encryptor.Encrypt(txtPassword.Text));
      
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    if (!bool.Parse(dr["UserSessionExists"].ToString()))
                    {
                    }
                    else
                    {
                     // Over here I am registering the starup script
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LoginError", "confirm('Ovverride ?');", true);
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "LoginError", "confirm('Ovverride ?');");              
                    }
                }
                else
                {
                    ErrorMessage = "Invalid login information supplied.";
                }
            }


    But the confirmation box is not showing. Please help me out !
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Apr 2013 Link to this post

    Hi,

    Try the following code to show radconfirm.
    C#:
    protected void Button2_Click(object sender, EventArgs e)
       {
           string radalertscript = "<script language='javascript'>function f(){callConfirm(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
           Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
       }
    JS:
    function callConfirm() {
            radconfirm('Are you sure?', confirmCallBackFn);
        }

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bibhudutta
    Bibhudutta avatar
    16 posts
    Member since:
    Jan 2012

    Posted 11 Apr 2013 Link to this post

    Thanks Shinu for the reply, but it did not work for me.
    I tries with this and it shows a confirmation box, but it does not do a post back to the server on 'OK' button click. Can you tell me how to do a post back on 'OK' button click.

    string markup = Format.EncodeJsString("This user has already logged in. Do you want to override current session ?");
    string errorScript = @"
        embedHtml({0});
        function embedHtml(result)
        {{
            confirm(result)
        }}";
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Confirm", string.Format(errorScript, markup), true);
  5. Bibhudutta
    Bibhudutta avatar
    16 posts
    Member since:
    Jan 2012

    Posted 11 Apr 2013 Link to this post

    I achieved it in this way,
    string overrideConfirmationScript = @"
        ShowOverrideConfirmation();
        function ShowOverrideConfirmation()
        {{ 
            if(confirm('This user has already logged in. Do you want to override current session ?'))
            {{ 
                __doPostBack( 'OverrideConfirmed', 'Override');
                return true;
            }}
        }}";
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Confirm", string.Format(overrideConfirmationScript), true);
Back to Top