i am trying to wrap my validation summary for createuserwizard to a modalpopup but dont knw hw to to call the javascript on createuserwizard1_createusererror event


javascript code on aspx

<script language="javascript" type="text/javascript">
// <! Javascript to show the modalpopup

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


</script>

and i am trying to call it here

protected void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e)
    {
       Page.ClientScript.RegisterStartupScript(this.GetType(), "addScript", "ShowModalDialog()", true);
        


    }

but its not doing anything

you are using ASP.NET AJAX UpdatePanel in your aspx page.
Then Page.ClientScript.RegisterStartupScript will not work.
We have to use ScriptManager.RegisterStartupScript.

you are using ASP.NET AJAX UpdatePanel in your aspx page.
Then Page.ClientScript.RegisterStartupScript will not work.
We have to use ScriptManager.RegisterStartupScript.

This is my full code..i am not using any updatepanel i think..im using the scriptmanager though thru master page

the idea is to show the modal pop for validation summary only wen der is any validation error..im successful in showing the modalpopup on pageloda event but it show even when er is no error for slight second


my 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:CustomValidator ID="CustomValidator1" runat="server" 
                 ErrorMessage="CustomValidator" Display="None" 
                 ValidationGroup="CreateUserWizard1"></asp:CustomValidator> 
         
              
        
         
        
         <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>
        
           
               <cc1:ModalPopupExtender ID="AddUserVS_ModalPopupExtender" runat="server" 
                   DynamicServicePath="" Enabled="True" TargetControlID="AddUserVS"  BackgroundCssClass="modalBackground " PopupControlID="Panel1">
               </cc1:ModalPopupExtender>
           
</asp:Content>

my code behind is

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


     
       
        
    
   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;
            //Label1_ModalPopupExtender.Show();
            
        }

        

    }



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

          CustomValidator1.ErrorMessage = CreateUserWizard1.DuplicateUserNameErrorMessage;
            
        }


    }    

         
        
    }

now in above code i am sucessfully able to show modalpopup on page load thru javascript but i want it to show only when der r errors...but it shows blank modalpop nyways even if der is now error


i.e y i am trying to run my javascript inside createuserwizard1_createusererror

iv tried the simple approcah too but its futile...

protected void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e)
    {
AddUserVS_ModalPopupExtender.Enabled=true;
        AddUserVS_ModalPopupExtender.Show();


    }

Create a separate aspx page for error message,say error.aspx,and try this code.

ScriptManager.RegisterStartupScript(this.GetType,"addScript", "window.showModalDialog('error.aspx','ErrorMessage','dialogHeight:290px;dialogWidth:500px;resizable:No; status:No;scroll:No;' )",true)

I hope that works!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.