I have a createuserwizard where I can create username.
The problem is, when I created a username and password, and hit 'Create User,' if there is already a duplicate username, it will show the error message that there is a username already. So, I must created a unique username. Once I successfully created a unique username, I click to go to the 'Home' page using 'Reponse.Redirect' and it does not take me to the 'Home' page, but automatically log me out of the system.
Here is what I can gather:
The code Home_Click
protected void btnHome_Click(object sender, EventArgs e) { ViewState["ID"] = null; ViewState["userName"] = null; //create a string variable for message string message; //create an email class Email email = new Email(); try { Response.Redirect("Home.aspx", false); } catch (Exception ex) { if ((ex.Message.ToString() == "Thread was being aborted.") || (ex.Message.ToString() == "{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}")) { Response.Redirect("Home.aspx", false); } else { message = ex.Message.ToString(); email.SendEmailError("User session logged out automatically. ", " Error: " + message); //redirect the user to the error page Response.Redirect("Error.aspx"); } } }
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#F7F6F3" BorderColor="#F7F6F3" BorderStyle="Solid" BorderWidth="1px" DuplicateUserNameErrorMessage="UserID already exist. Please enter a different Username." FinishCompleteButtonText="" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" Height="72px" InvalidPasswordErrorMessage="Password must be a minimum of {0} characters and contain {1} Non-alphanumeric characters." oncreateduser="CreateUserWizard1_CreatedUser" style="font-size: medium; font-family: 'Times New Roman'; text-align: center;" Width="809px"><SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" /><SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" /><ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /><NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /><HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" /><CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /><TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /><StepStyle BorderWidth="0px" /><WizardSteps><asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"><ContentTemplate><table align="center" style="height: 137px; width: 729px;"><tr><td class="style72" style="text-align: right"><asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User ID: </asp:Label></td><td class="style73"><asp:TextBox ID="UserName" runat="server" Width="180px"></asp:TextBox><asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User ID is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator></td><td class="style73" style="text-align: center"></td></tr><!--tr><td class="td4"><asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email" Visible="false">E-mail:</asp:Label></td><td class="td5"></td><td class="td4"><asp:TextBox ID="Email" runat="server" height="22px" width="128px" Visible="false"></asp:TextBox></td></tr--><tr><td class="style71" style="text-align: right"><asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" style="font-family: 'Times New Roman', Times, serif">Password: </asp:Label></td><td class="style66" style="text-align: left"><asp:TextBox ID="Password" runat="server" style=" border:solid 2px #cccccc;border-top: solid 2px #a0a0a0; color:#999999; background-color:#eeeeee;" TextMode="Password" Width="180px"></asp:TextBox><asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td><td class="style66" style="text-align: center"> </td></tr><tr><td class="style70"><asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password: </asp:Label></td><td class="style62"><asp:TextBox ID="ConfirmPassword" runat="server" style=" border:solid 2px #cccccc;border-top: solid 2px #a0a0a0; color:#999999; background-color:#eeeeee;" TextMode="Password" Width="180px"></asp:TextBox><asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator></td><td class="style62"> </td></tr><!--tr><td class="td4"><asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question" Visible="false">Security Question:</asp:Label></td><td class="td5"></td><td class="td4"><asp:TextBox ID="Question" runat="server" height="22px" width="128px" Visible="false"></asp:TextBox></td></tr><tr><td class="td4"><asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer" Visible="false">Security Answer:</asp:Label></td><td class="td5"></td><td class="td4"><asp:TextBox ID="Answer" runat="server" height="22px" width="128px" Visible="false"></asp:TextBox></td></tr--><tr><td class="style69" colspan="3" style="text-align: center"><asp:Panel ID="pnlMessages" runat="server" Height="35px" style="color: #FF0000"><asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." style="text-align: center" ValidationGroup="CreateUserWizard1"></asp:CompareValidator><br /><asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal><asp:Literal ID="DupUsername" runat="server" EnableViewState="False"></asp:Literal></asp:Panel></td></tr></table></ContentTemplate><CustomNavigationTemplate><table border="0" cellspacing="5" style="width:100%;height:100%;"><tr align="right"><td align="right" colspan="0" style="text-align: center"><asp:Button ID="StepNextButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="MoveNext" Font-Names="Verdana" ForeColor="#284775" Text="Create User" ValidationGroup="CreateUserWizard1" /></td></tr></table></CustomNavigationTemplate></asp:CreateUserWizardStep><asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"><ContentTemplate><table border="0" style="font-family:Verdana;font-size:100%;height:82px;width:801px;"><tr><td align="center" style="color:White;font-weight:bold;"> </td></tr><tr><td> </td></tr><tr><td align="center" style="text-align: center"><asp:Button ID="ContinueButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue" Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" Visible="False" /></td></tr></table></ContentTemplate></asp:CompleteWizardStep></WizardSteps></asp:CreateUserWizard>