Click here to Skip to main content
16,022,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table and in the table one textbox
XML
<asp:TextBox ID="TextBox1" runat="server">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Insert the Category" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>

<asp:Button ID="Button5" runat="server" onclick="Button1_Click" Text="Submit"  Font-Bold="true"/>

<asp:Button
            ID="Button8" runat="server" onclick="Button4_Click" Text="Category View" />

It is validated on both button but I want only on button5
Posted
Updated 5-Dec-11 19:06pm
v3

Try adding ValidationGroup in button5, RFV and Textbox1 as show below.

XML
<asp:TextBox ID="TextBox1" runat="server"  ValidationGroup="abc">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Insert the Category" ControlToValidate="TextBox1" ValidationGroup="abc">< /asp:RequiredFieldValidator>

<asp:Button ID="Button5" runat="server" onclick="Button1_Click" Text="Submit"  Font-Bold="true" ValidationGroup="abc"/>

<asp:Button
            ID="Button8" runat="server" onclick="Button4_Click" Text="Category View" />


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
v3
Hi try this code:

XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="btn" ErrorMessage="Insert the Category" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>


                        <asp:Button ID="Button5" runat="server" onclick="Button1_Click" Text="Submit" ValidationGroup="btn" Font-Bold="true"/>

                        <asp:Button ID="Button8" runat="server" onclick="Button4_Click" Text="Category View" />

HTML

 
Share this answer
 
Comments
Md. Azizur Rahman 6-Dec-11 1:30am    
Hi, I am Aziz. I have faced a problem. That's bellow,
I have written a nested ListView in ASP.NET. That's ListView inside a ListView.
But the datapager of inner ListView doesn't work properly. Please give me the best solution with an Example that's work properly.
On which Button you don't want to do validation.
1.Right click on button
2.Go in Property
3.Set CausesValidation property to False.
It will works.
 
Share this answer
 
in the textbox,button and required field validator set the validation group.

example:
C#
button:
<asp:button id="Button5" runat="server" onclick="Button5_Click" text="Submit" font-bold="true" validationgroup="GroupToValidate" xmlns:asp="#unknown" />

textbox
<asp:textbox id="TextBox1" runat="server" validationgroup="GroupToValidate" xmlns:asp="#unknown"></asp:textbox>

required field validator

<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" validationgroup="btn" errormessage="Insert the Category" controltovalidate="TextBox1" xmlns:asp="#unknown"></asp:requiredfieldvalidator>


note: button, textbox and requiredFielValidator should have the same validation group text (ex. ValidationGroup="GroupToValidate")

hope it helps

don't forget to vote if it helps you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900