Skytzo
asked on
Validation Triggers outside Updatepanel are being triggered.. Why?
I have a single page with both a loginview and a createuserwizard control. If the user creates a login, I want it to automatically login, and if the user chooses to simply login, they can do so.
I have tried to separate out each control with an updatepanel. I have templated each control, so it should work. The problem is that when I select the login button for the login control, it appears to trigger the validation controls inside the createuserwizard which is outside of its updatepanel. I cannot understand why this is occuring, and how to stop it from happening.
I have tried to separate out each control with an updatepanel. I have templated each control, so it should work. The problem is that when I select the login button for the login control, it appears to trigger the validation controls inside the createuserwizard which is outside of its updatepanel. I cannot understand why this is occuring, and how to stop it from happening.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Bizential.WebApp.Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>
<asp:UpdatePanel ID="LoginUpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<div id="login">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<asp:LoginName ID="LoginName1" runat="server" /> - <asp:LoginStatus ID="LoginStatus1" LogoutText="LOGOUT" runat="server" />
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Login ID="BizLogin" runat="server" VisibleWhenLoggedIn="false" OnAuthenticate="Login1_Authenticate" >
<LayoutTemplate>
<asp:Label ID="Label1" AssociatedControlID="UserName" runat="server">Email</asp:Label>
<asp:TextBox runat="server" ID="UserName" CssClass="loginFields"></asp:TextBox>
<asp:requiredfieldvalidator id="UserNameRequired" runat="server" ControlToValidate="UserName" Text="*"></asp:requiredfieldvalidator>
<asp:Label ID="Label2" AssociatedControlID="Password" runat="server">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" CssClass="loginFields" TextMode="Password"></asp:TextBox>
<asp:requiredfieldvalidator id="PasswordRequired" runat="server" ControlToValidate="Password" Text="*"></asp:requiredfieldvalidator>
<asp:Button id="loginButton" CommandName="Login" runat="server" Text="Login"></asp:Button></button>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:CreateUserWizard id="CreateUserWizard1" Runat="server" OnCreatingUser="OnCreatingUser" LoginCreatedUser="true" OnContinueButtonClick="ContinueButtonClick">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizard1Step" runat="server">
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>First Name:</td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" ControlToValidate="FirstName"
ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName"
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:TextBox runat="server" ID="Email" Visible="false"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<asp:UpdatePanel ID="LoginUpdatePanel" runat="server" UpdateMode="con ditional">
<ContentTemplate>
<div id="login">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<asp:LoginName ID="LoginName1" runat="server" /> - <asp:LoginStatus ID="LoginStatus1" LogoutText="LOGOUT" runat="server" />
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Login ID="BizLogin" runat="server" VisibleWhenLoggedIn="false " OnAuthenticate="Login1_Aut henticate" >
<LayoutTemplate>
<asp:Label ID="Label1" AssociatedControlID="UserN ame" runat="server">Email</asp: Label>
<asp:TextBox runat="server" ID="UserName" CssClass="loginFields"></a sp:TextBox >
<asp:requiredfieldvalidato r id="UserNameRequired" runat="server" ValidationGroup="vg1" ControlToValidate="UserNam e" Text="*"></asp:requiredfie ldvalidato r>
<asp:Label ID="Label2" AssociatedControlID="Passw ord" runat="server">Password</a sp:Label>
<asp:TextBox runat="server" ID="Password" CssClass="loginFields" TextMode="Password"></asp: TextBox>
<asp:requiredfieldvalidato r id="PasswordRequired" runat="server" ValidationGroup="vg1" ControlToValidate="Passwor d" Text="*"></asp:requiredfie ldvalidato r>
<asp:Button id="loginButton" CommandName="Login" runat="server" ValidationGroup="vg1" Text="Login"></asp:Button> </button>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loginButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:CreateUserWizard id="CreateUserWizard1" Runat="server" OnCreatingUser="OnCreating User" LoginCreatedUser="true" OnContinueButtonClick="Con tinueButto nClick">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizard1Step" runat="server">
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>First Name:</td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextB ox>
<asp:RequiredFieldValidato r ID="FirstNameRequired" runat="server" ValidationGroup="vg2" ControlToValidate="FirstNa me"
ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUse rWizard1"> *</asp:Req uiredField Validator>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextB ox>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidato r runat="server" ID="RequiredFieldValidator 9" ValidationGroup="vg2" ControlToValidate="UserNam e"
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidato r runat="server" ID="RequiredFieldValidator 10" ValidationGroup="vg2" ControlToValidate="Passwor d"
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidato r runat="server" ID="RequiredFieldValidator 13" ValidationGroup="vg2" ControlToValidate="Confirm Password"
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:TextBox runat="server" ID="Email" Visible="false"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ValidationGroup="vg2" ControlToCompare="Password "
ControlToValidate="Confirm Password" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValid ator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></ asp:Litera l>
</td>
</tr>
</table>
WHERE IS YOUR BUTTON? make sure button is created and set its attribute ValidationGroup="vg2"
</ContentTemplate>
</asp:CreateUserWizardStep >
</WizardSteps>
</asp:CreateUserWizard>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="yoursecondbutto n" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<ContentTemplate>
<div id="login">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<asp:LoginName ID="LoginName1" runat="server" /> - <asp:LoginStatus ID="LoginStatus1" LogoutText="LOGOUT" runat="server" />
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Login ID="BizLogin" runat="server" VisibleWhenLoggedIn="false
<LayoutTemplate>
<asp:Label ID="Label1" AssociatedControlID="UserN
<asp:TextBox runat="server" ID="UserName" CssClass="loginFields"></a
<asp:requiredfieldvalidato
<asp:Label ID="Label2" AssociatedControlID="Passw
<asp:TextBox runat="server" ID="Password" CssClass="loginFields" TextMode="Password"></asp:
<asp:requiredfieldvalidato
<asp:Button id="loginButton" CommandName="Login" runat="server" ValidationGroup="vg1" Text="Login"></asp:Button>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loginButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:CreateUserWizard id="CreateUserWizard1" Runat="server" OnCreatingUser="OnCreating
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizard1Step"
<ContentTemplate>
<table>
<tr>
<th>User Information</th>
</tr>
<tr>
<td>First Name:</td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextB
<asp:RequiredFieldValidato
ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUse
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextB
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidato
ErrorMessage="Username is required." />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidato
ErrorMessage="Password is required." />
</td>
</tr>
<tr>
<td>Confirm Password:</td>
<td>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidato
ErrorMessage="Confirm Password is required." />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:TextBox runat="server" ID="Email" Visible="false"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server" ValidationGroup="vg2" ControlToCompare="Password
ControlToValidate="Confirm
</td>
</tr>
<tr>
<td colspan="2">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></
</td>
</tr>
</table>
WHERE IS YOUR BUTTON? make sure button is created and set its attribute ValidationGroup="vg2"
</ContentTemplate>
</asp:CreateUserWizardStep
</WizardSteps>
</asp:CreateUserWizard>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="yoursecondbutto
</Triggers>
</asp:UpdatePanel>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was unable to override the default button in a CreateUserWizard control. Instead I found that I can set the ValidationGroup for controls within the CreateUserWizard to the ID of the CreateUserWizard instead.
Thanks
Thanks
When set to Always, the UpdatePanel is updated on every postback raised from anywhere in the page, so from controls inside the panel, inside other panels or just on the page.
When set to Conditional, the UpdatePanel will be updated only on postback originated by controls inside the panel or from the triggers specified.
http://codeclimber.net.nz/archive/2007/05/24/updatemode-default-value-for-the-updatepanel-is-always.aspx