modalpopup validation summary !!

Last post 10-21-2009 4:14 PM by neomatrix2. 4 replies.

Sort Posts:

  • modalpopup validation summary !!

    10-16-2009, 6:20 PM
    • Member
      1 point Member
    • neomatrix2
    • Member since 09-09-2009, 10:52 AM
    • Posts 23


    heres my code which shows a modal pop up for validation summary on create wizard

    i gt two problems

    1.. i am not able to show duplicateusername error to modalpopup validation summary even when i hv the correct validationgroup for username control

    2.. when i click createuser (when der is no error) i still see the modalpop  though for just flash of a second or two...how to stop that??


    Here is my running code


    .aspx file

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="login1.aspx.cs" Inherits="login1" Title="Untitled Page" %>

    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">


    <style type="text/css">

    .modalBackground {
                background-color: Gray;
                filter: alpha(opacity=30);
                opacity: 0.3;}
            .modalPopup {
                width: 400px;
                height: 300px;
                background-color: #076DAB;
                color: #FFFFFF;
                border-color: #000000;
                border-width: 1px;
                border-style: solid;
                text-align: center;
                cursor: move;
                font-size: medium;}

           

        </style>

    <script language="javascript" type="text/javascript">


    // <! Javascript to show the modalpopup

    function ShowModalDialog()
    {
     Page_ClientValidate();
     if(!Page_IsValid)
     $find('<%=AddUserVS_ModalPopupExtender.ClientID%>').show();
    }


    </script>

    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


               <!-- Create User wizard-->
               
                   <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"  RequireEmail="False"
                       oncreatinguser="CreateUserWizard1_CreatingUser" CssClass="cw"
                       Width="352px" oncreateusererror="CreateUserWizard1_CreateUserError"
                       >
                       <WizardSteps>
                           <asp:CreateUserWizardStep runat="server">
                               <ContentTemplate>
                                   <table border="0" >
                                       
                                       <tr>
                                           <td align="right">
                                               <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User
                                               Name:</asp:Label>
                                           </td>
                                           <td>
                                               <asp:TextBox ID="UserName" runat="server" CssClass="texty" ></asp:TextBox>
                                                 <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
                                                   ControlToValidate="UserName" ErrorMessage="Email is required."
                                                   ToolTip="Email is required." ValidationGroup="CreateUserWizard1"
                                                   Visible="True" EnableViewState="False" Display="None">*</asp:RequiredFieldValidator>
                                                   <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                                                   runat="server" ControlToValidate="UserName"
                                                    ErrorMessage="Email address is not valid"
                                                   ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                                   ValidationGroup="CreateUserWizard1" Display="None"></asp:RegularExpressionValidator>
                                           </td>
                                       </tr>
                                       <tr>
                                           <td align="right">
                                               <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                           </td>
                                           <td>
                                               <asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="texty"
                                                   ></asp:TextBox>
                                               <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
                                                   ControlToValidate="Password" ErrorMessage="Password is required."
                                                   ToolTip="Password is required." ValidationGroup="CreateUserWizard1"
                                                   Display="None">*</asp:RequiredFieldValidator>
                                                   
                                           </td>
                                       </tr>
                                       <tr>
                                           <td align="right">
                                               <asp:Label ID="ConfirmPasswordLabel" runat="server"
                                                   AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
                                           </td>
                                           <td>
                                               <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password" CssClass="texty"
                                                   ></asp:TextBox>
                                               <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
                                                   ControlToValidate="ConfirmPassword"
                                                   ErrorMessage="Confirm Password is required."
                                                   ToolTip="Confirm Password is required."
                                                   ValidationGroup="CreateUserWizard1" Display="None">*</asp:RequiredFieldValidator>
                                           </td>
                                       </tr>
                                                         
                                   
                                                <tr>
                                           <td align="center" colspan="2">
                                       
                                               <asp:CompareValidator ID="PasswordCompare" runat="server"
                                                   ControlToCompare="Password" ControlToValidate="ConfirmPassword"
                                                   Display="None"
                                                   ErrorMessage="The Password and Confirmation Password must match."
                                                   ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                               </td>
                                       </tr>
                                       <tr>
                                           <td align="center" colspan="2" style="color:Red;">
                                               <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                       
                                           </td>
                                       </tr>
                                  </table>
                                        
                               </ContentTemplate>                    
                           </asp:CreateUserWizardStep>    
                            <asp:CompleteWizardStep runat="server">
                            </asp:CompleteWizardStep>
                            </WizardSteps>
                    </asp:CreateUserWizard>
               
             <!-- Panel containing validation summary-->
             
             <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" >
             <asp:ValidationSummary runat="server" ID="AddUserVS" DisplayMode="BulletList" ValidationGroup="CreateUserWizard1"
             HeaderText="<b>Please review the following errors:</b>" ShowMessageBox="False" />
             <input type="button" value="OK" onclick="$find('<%= AddUserVS_ModalPopupExtender.ClientID %>').hide();"/>
            </asp:Panel>
             

    </asp:Content>


    .cs file

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class login1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                foreach (Control ctrl in CreateUserWizard1.Controls)
                {
                    FindButtons(ctrl);
                }
            }
            
        // find the createuser button


       private void FindButtons(Control ctrl)
        {
            if (ctrl.GetType() == typeof(Button))
            {
                Button btn = (Button)ctrl;
                if (btn.ID == "StepNextButtonButton")
                {
                    
                    btn.Attributes.Add("onclick", "ShowModalDialog();");
                    btn.Attributes.Add("onmouseup", "ShowModalDialog();");

                }
            }
            foreach (Control ctrl2 in ctrl.Controls)
            {
                FindButtons(ctrl2);
            }
        }
          

    protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
        {
            if (Page.IsValid)
            {
                CreateUserWizard cuw = (CreateUserWizard)sender;
                cuw.Email = cuw.UserName;
              
                
            }
            
           

        }



        protected void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e)
        {
            string ErrorMessage = "";
            if (e.CreateUserError == MembershipCreateStatus.DuplicateUserName)

                ErrorMessage = " Duplicate email , The email entered is already used!";

        }
    }



    As u can see iv also tried to change the default error message to my custom error message but thats not happening either...if anybdy can lite on wht im doing wrong wud certainly be apprecialble

  • Re: modalpopup validation summary !!

    10-16-2009, 8:58 PM
    • Member
      1 point Member
    • neomatrix2
    • Member since 09-09-2009, 10:52 AM
    • Posts 23

    iv googled nd found that for database related validation i hv to use customvalidator...agreed much!!!

    now when i put my customvalidator inside my panel and set its validationgroup to same as validationsummary i shud hv the customvalidator error as validationsummary errors in modalpopup but im hving no success here's what i added tothe  above code

    .aspx file

    <!-- Panel containing validation summary-->
             
          
       <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" >
             
                 <asp:CustomValidator ID="CustomValidator1" runat="server"
                     ErrorMessage="CustomValidator" Display="Static"
                     ValidationGroup="CreateUserWizard1"></asp:CustomValidator>
            
    <asp:ValidationSummary runat="server" ID="AddUserVS" DisplayMode="BulletList" ValidationGroup="CreateUserWizard1"
             HeaderText="<b>Please review the following errors:</b>" ShowMessageBox="False" />
             <input type="button" value="OK" onclick="$find('<%= AddUserVS_ModalPopupExtender.ClientID %>').hide();"/>
            </asp:Panel>


    and in code behind iam trying to customvalidate for duplicate username error message

    .cs  file


    protected void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e)
        {
            if (e.CreateUserError == MembershipCreateStatus.DuplicateUserName)
            {
                CreateUserWizard1.DuplicateUserNameErrorMessage = " Duplicate email , The email entered is already used!";
                

                CustomValidator1.ErrorMessage = CreateUserWizard1.DuplicateUserNameErrorMessage;
                
            }
    }

    can anybody help me to show the customvalidator on the same modalpopup of validationsummary and also ....


    secondly...i want the modalpop up to show only when der r errors...it fires  as blank modalpopup evrytym i click create user..i knw imust put sm condition but i am not sure what!!...


    Note: i am using email as username

  • Re: modalpopup validation summary !!

    10-21-2009, 10:23 AM

    Hi neomatrix2,

    Please refer to my reply in this thread:
    http://forums.asp.net/p/1372125/2902586.aspx#2902586

    Best regards,

    Zhi-Qiang Ni

    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: modalpopup validation summary !!

    10-21-2009, 4:09 PM
    • Member
      1 point Member
    • neomatrix2
    • Member since 09-09-2009, 10:52 AM
    • Posts 23
    Hi zhi, Thanku for your reply but i got my validation summary inside Panel1 which i want to modal pop up.....i am succesful with javascript in doing so for required validators and compare validators but not with custom validators which validates database errors like duplicate username or email... can u please help me how can i use ur code to pop up my validation summary
  • Re: modalpopup validation summary !!

    10-21-2009, 4:14 PM
    • Member
      1 point Member
    • neomatrix2
    • Member since 09-09-2009, 10:52 AM
    • Posts 23
    jksksl
Page 1 of 1 (5 items)