Question

 <asp:ComboBox ID="ddlto" runat="server" IncrementalFilteringMode="StartsWith"
                DataSourceID="XmlDatasource1" TextField="name" ValueField="name"
                Width="100%" DataTextField="name" DataValueField="name" MaxLength="0" style="display: inline;" 
                                                AutoCompleteMode="Suggest" 
                                                onselectedindexchanged="ddlto_SelectedIndexChanged" />

                                        </td></br>

                          <asp:CompareValidator ID="cm1" runat="server" Operator="NotEqual" Type="string" ControlToValidate="ddlfrom" ControlToCompare="ddlto" ErrorMessage="The 'Departure City' and 'Destination City' cannot be same. Please re-type." ForeColor="red" 
BackColor="yellow" Display="Dynamic" SetFocusOnError="True"> </asp:CompareValidator

It is working properly for that page but when i am clicknig on any other button of that page to redirect to other page again the same messaage of compare validator is printing and i cannot redirect to another page.Means i have 3 pages bus,train and flight when i am removing this compare validator code then i am able to redirext the pages..but when i place these code..in my asp page then, when i click on flight button to redirect to the flight page,it is showing the same message as i have typd in compare validator code.it is not redirecting.PLZZ HELP

Was it helpful?

Solution

You need to add ValidationGroup property to validator and button which should do validation

<asp:CompareValidator ID="ddlto" ... ValidationGroup="MyValidation"... />

<asp:Button ID="MyBtn" ... ValidationGroup="MyValidation"... />

Just make sure, that validator and button have same group.

OTHER TIPS

use vlaidation group property

<asp:CompareValidator ID="cm1" runat="server" Operator="NotEqual" Type="string"
ControlToValidate="ddlfrom" ControlToCompare="ddlto" ErrorMessage="The 'Departure City'     
and 'Destination City' cannot be same. Please re-type." ForeColor="red" 
BackColor="yellow" Display="Dynamic" SetFocusOnError="True"> </asp:CompareValidator>

vlaidationgroup="abc"

here add this prprety along with other properties and give same to that button also then it will be cleared.

Here is some documentation about the ValidationGroup attribute for Form Elements. http://msdn.microsoft.com/en-us/library/ms227424(v=vs.100).aspx

The basic idea is to group all the elements you want to be validated when you click a specific button, by identifying them with the same ValidationGroup value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top