how to use more than one validation in one page - c#

I have 2 radio button (radiobtn1 and radiobtn2) in one group and 4 text box which names are a, b, c, d. And end of the page there is standard button. I add asp:requiredFieldValidators to all of textboxes. So when I clicked my button asp:validationsummary works for all of textboxes.
I want to do that if radiobtn1 was clicked, validationsummary should work for textbox a and b, if radiobtn2 was clicked, validationsummary should work for should textbox c and d.
how can I do that?
thx.

this is working as of your requirement..
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="*" Font-Size="Medium" ForeColor="Red" ValidationGroup="group 1">*</asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="*" Font-Size="Medium" ForeColor="Red" ValidationGroup="group 1">*</asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" ErrorMessage="*" Font-Size="Medium" ForeColor="Red" ValidationGroup="group 2">*</asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox4" ErrorMessage="*" Font-Size="Medium" ForeColor="Red" ValidationGroup="group 2">*</asp:RequiredFieldValidator>
<br />
<br />
<br />
<br />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" Text="valid first 2" CausesValidation="True" GroupName="g" ValidationGroup="group 1"/>
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" Text="valid last 2" CausesValidation="True" GroupName="g" ValidationGroup="group 2" />
<br />
<br />
</div>
</form>

Related

Replace a TextBox based on DropDownList choice

When I choose an element from DropDownList, I want a TexBox to disappear and to be replaced by another one in the same exact position.
For example: I have a DropDownList filled with categories of SI equipments, Laptop, Desktop, Display etc. So when I choose Display, the RAM, CPU, HARD DISK textboxes must disappear and INCH TextBox should replace RAM TextBox.
This is my code:
<div>
<label id="l1" class="label" >Numéro de série:</label>
<asp:TextBox ID="NumSerie" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l8" class="label"> Systeme d'exploitation: </label>
<asp:TextBox ID="SystemEx" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<asp:Button class="NButton" ID="Button1" runat="server" Height="38px" Text="Ajouter" Width="140px" OnClick="Button1_Click" />
</div>
<div>
<label id="l2" class="label">Désignation:</label>
<asp:TextBox ID="Designation" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l9" class="label"> Processeur:</label>
<asp:TextBox ID="Cpu" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<asp:Button CssClass="NButton" ID="Button2" runat="server" Height="38px" Text="Modifier" Width="140px" />
</div>
<div>
<label id="l3" class="label">
<asp:TextBox ID="Marque" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l10" class="label">Ram: </label>
<asp:TextBox ID="Ram" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<asp:Button CssClass="NButton" ID="Button3" runat="server" Height="38px" Text="Supprimer" Width="140px" />
</div>
<div>
<label id="l4" class="label">
<br />
Catégorie:</label>
<asp:DropDownList ID="IdCategorie" CssClass="textbox" runat="server" Height="32px" Width="200px"/>
<label id="l11" class="label"> Capacité destockage:</label>
<asp:TextBox ID="CapaciteSt" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<asp:Button CssClass="NButton" ID="Button4" runat="server" Height="38px" Text="Rechercher" Width="140px" />
</div>
<div>
<label id="l5" class="label">
<br />
Code de fournisseur:</label>
<asp:DropDownList ID="CodeFour" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l12" class="label"></label>
<asp:TextBox ID="Remise" class="textbox" runat="server" Height="32px" Width="200px" />
<asp:Label ID="l15" runat="server" CssClass="label" Text="ID Equi:"></asp:Label>
<asp:TextBox CssClass="Rtextbox" ID="TextBox1" runat="server" Height="22px" Width="70px"></asp:TextBox>
</div>
<div>
<label id="l6" class="label"></label>
<asp:TextBox ID="Prix" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l13" class="label">Modele </label>
<asp:TextBox Id="Modele" CssClass="textbox" runat="server" Height="32px" Width="200px" />
</div>
<div>
<label id="l7" class="label"> </label>
<asp:TextBox ID="EtatGarantie" CssClass="textbox" runat="server" Height="32px" Width="200px" />
<label id="l14" class="label"></label>
<asp:TextBox ID="Pouces" CssClass="textbox" runat="server" Height="32px" Width="200px" />
</div>
<asp:Button CssClass="NButton" ID="Button5" runat="server" Text="<<" Width="55px" />
There is no need to replace the textbox. but it depends on if different selected items have different number of texboxes.
First set on your DropDownList AutoPostBack="true" then
You can simply change the placeholde runtime on SelectedIndexChanged of DropDownList like this
protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)
{
txtDOB.Attributes.Add("placeholder", ddlProducts.SelectedItem.Text);
}
you can use same textbox for any item you selected.

Putting validators disturbs panel layout

when i put RequiredFieldValidator in asp.net page then it disturbs page layout. It works in all places but in specific places it disturbs page layout.
Before Putting Validator:
<asp:Panel ID="pnlSearchComplaint" Visible="false" BackColor="#dbdbdb"
runat="server" Width="400px">
<br />
<label>Search By Subject</label>
<asp:TextBox ID="txtSearchCompBySubject" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txtSearchCompBySubject" ErrorMessage="Enter Subject"
ForeColor="Red" ValidationGroup="GroupSearchCompSubject">Enter Subject
</asp:RequiredFieldValidator>
<br/>
<asp:Button ID="btnSearchBySubject" ValidationGroup="GroupSearchCompSubject"
CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" OnClick="btnSearchBySubject_Click" />
<asp:GridView ID="gridViewComplaintsBySubject" AllowPaging="true" OnPageIndexChanging="gridViewComplaintsBySubject_PageIndexChanging" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" OnSelectedIndexChanged="gridViewComplaintsBySubject_SelectedIndexChanged" Width="408px">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" ForeColor="white" />
</asp:GridView>
<br />
<label>Search By Date</label>
<asp:Label ID="lblDateFrom" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="txtFromDate" runat="server" ></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderFromDate" TargetControlID="txtFromDate" runat="server">
</asp:CalendarExtender>
<asp:Label ID="lblDateTo" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderToDate" TargetControlID="txtToDate" runat="server">
</asp:CalendarExtender>
<asp:Button ID="btnSearchByDate" CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" OnClick="btnSearchByDate_Click" />
<asp:GridView ID="gridViewComplaintsByDate" AllowPaging="true" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" Width="408px" OnPageIndexChanging="gridViewComplaintsByDate_PageIndexChanging" OnSelectedIndexChanged="gridViewComplaintsByDate_SelectedIndexChanged">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" ForeColor="white" />
</asp:GridView>
<br />
</asp:Panel>
After Putting Validator:
Code:
<asp:Panel ID="pnlSearchComplaint" Visible="false" BackColor="#dbdbdb"
runat="server" Width="400px">
<br />
<label>Search By Subject</label>
<asp:TextBox ID="txtSearchCompBySubject" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txtSearchCompBySubject" ErrorMessage="Enter Subject"
ForeColor="Red" ValidationGroup="GroupSearchCompSubject">Enter Subject
</asp:RequiredFieldValidator>
<br/>
<asp:Button ID="btnSearchBySubject" ValidationGroup="GroupSearchCompSubject"
CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" OnClick="btnSearchBySubject_Click" />
<asp:GridView ID="gridViewComplaintsBySubject" AllowPaging="true" OnPageIndexChanging="gridViewComplaintsBySubject_PageIndexChanging" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" OnSelectedIndexChanged="gridViewComplaintsBySubject_SelectedIndexChanged" Width="408px">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" ForeColor="white" />
</asp:GridView>
<br />
<label>Search By Date</label>
<asp:Label ID="lblDateFrom" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="txtFromDate" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="txtFromDate" ErrorMessage="Enter Subject"
ForeColor="Red" ValidationGroup="GroupSearchCompSubject">Enter Subject
</asp:RequiredFieldValidator>
<asp:CalendarExtender ID="CalendarExtenderFromDate" TargetControlID="txtFromDate" runat="server">
</asp:CalendarExtender>
<asp:Label ID="lblDateTo" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderToDate" TargetControlID="txtToDate" runat="server">
</asp:CalendarExtender>
<asp:Button ID="btnSearchByDate" CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" OnClick="btnSearchByDate_Click" />
<asp:GridView ID="gridViewComplaintsByDate" AllowPaging="true" AutoGenerateSelectButton="true" runat="server" CssClass="mGrid" Width="408px" OnPageIndexChanging="gridViewComplaintsByDate_PageIndexChanging" OnSelectedIndexChanged="gridViewComplaintsByDate_SelectedIndexChanged">
<EmptyDataRowStyle BorderStyle="None" ForeColor="Red" BorderWidth="0px" />
<EmptyDataTemplate>
No Data Found for this Input. Try Again.
</EmptyDataTemplate>
<SelectedRowStyle CssClass="selected-row" ForeColor="white" />
</asp:GridView>
<br />
</asp:Panel>
Please set the "Display='dynamic'" property in your Validation control.
<asp:RequiredFieldValidator Display="Dynamic"></asp:RequiredFieldValidator>
If you do not want disturb your UI when it shows the message then
<asp:RequiredFieldValidator Display="Dynamic" ErrorMessage="*" ToolTip="Set your message here"></asp:RequiredFieldValidator>
Edit 1:
<label>
Search By Date</label>
<asp:Label ID="lblDateFrom" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="txtFromDate" runat="server"></asp:TextBox>
<asp:Label ID="lblDateTo" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
<div>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator9" runat="server" ControlToValidate="txtFromDate"
ErrorMessage="Enter Subject" ForeColor="Red" ValidationGroup="GroupSearchCompSubject">Enter Subject
</asp:RequiredFieldValidator>
</div>
<asp:Button ID="btnSearchByDate" CssClass="btn btn-success" runat="server" Text="Search"
ClientIDMode="Static" />

Can't access dropdownlist in code behind

I am new and learning ASP.Net webforms. I have a DropDownList here:
<asp:DropDownList id="DropDownList1" runat="server">
</asp:DropDownList>
I am trying to access it by typing "DropDownList1" in my Page_Load event. but Intellisense doesn't show DropDownList1. So I assume I am doing something wrong but don't understand what is wrong.
I'm trying to access DropDownList so I can programmatically populate it with numbers.
EDIT: if my dropdownlist is inside another control, then I'm not seeing it:
<%# Page Title="Register" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Fake_Coupon_Site.Account.Register" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Use the form below to create a new account.</h2>
<h3>Suggested Readingfor <%= DateTime.Now.ToString("dddd, MMMM dd")%></h3>
</hgroup>
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatedUser="RegisterUser_CreatedUser">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="RegisterUserWizardStep">
<ContentTemplate>
<p class="message-info">
Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
</p>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RegularExpressionValidator runat="server" ControlToValidate="UserName" ValidationExpression=".{3,50}"
CssClass="field-validation-error" ErrorMessage="The user name field needs to be 3 to 50 characters." />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" style="margin-left:-325px;"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Email">Email address</asp:Label>
<asp:TextBox runat="server" ID="Email" TextMode="Email" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
CssClass="field-validation-error" ErrorMessage="The email address field is required." />
</li>
<li>
<asp:DropDownList id="DropDownList1" runat="server">
</asp:DropDownList>
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="ConfirmPassword">Confirm password</asp:Label>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The confirm password field is required." />
<asp:CompareValidator runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
</li>
</ol>
<asp:Button runat="server" CommandName="MoveNext" Text="Register" />
</fieldset>
</ContentTemplate>
<CustomNavigationTemplate />
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>
What you need is this:
DropDownList DropDownList1 = (DropDownList)RegisterUserWizardStep.ContentTemplateContainer.FindControl("DropDownList1");
Since it's in a different NamingContainer than the Page you need to use FindControl to get it:
DropDownList DropDownList1= (DropDownList)RegisterUserWizardStep.FindControl("DropDownList1");

ASP.NET: Using Eval in an if statement

I have a repeater. In the past, each item in the repeater had an associated text box. But, now I added an attribute to the repeated item that needs to specify if a text box, larger text box, or check box is used for that item.
Here is what my aspx code looks like:
<%if (Eval("DisplayType") == "LargeBox") { %>
<asp:TextBox ID="largeBoxAnswer" Rows="8" runat="server" Width="200" MaxLength="2000" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="largeBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
<%} %>
<%else if (Eval("DisplayType") == "CheckBox") { %>
<asp:TextBox ID="checkBoxAnswer" runat="server" Width="200" MaxLength="100" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="checkBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
<%} %>
<%else { %>
<asp:TextBox ID="txtAnswer" runat="server" Width="200" MaxLength="100" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
<%} %>
This is not working and I get the following error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
I found quite a bit about this error, but nothing that really helped with this particular issue.
Am I even going about doing something like this the correct way? I am not super experienced with asp.net, so I am open to a different approach to this issue. If this is the best way, how do I move the logic to the code behind so this works properly?
The error is telling you that your if statement is not actually in the databinding context, so even if your Eval did work, what it trys to Eval... "DisplayRule" ... doesnt actually exist at that line.
Have a look at this link; eval in if statement?
From what those guys are saying, your answer may lie in ElementIfTrue, or the Visible property.
So you might end up with something like this;
<asp:TextBox ID="largeBoxAnswer" ElementIfTrue='<%# Eval("DisplayRule") == "LargeBox" %>' Rows="8" runat="server" Width="200" MaxLength="2000" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="largeBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
<asp:TextBox ID="checkBoxAnswer" ElementIfTrue='<%# Eval("DisplayRule") == "CheckBox" %>' runat="server" Width="200" MaxLength="100" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="checkBoxAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
<asp:TextBox ID="txtAnswer" ElementIfTrue='<%# Eval("DisplayRule") == "**notsure**" %>' runat="server" Width="200" MaxLength="100" EvaluationQuestionID='<%# Eval("EvaluationQuestionId") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtAnswer" Display="dynamic" Font-Bold="true" ErrorMessage="*" />
... I don't think that solves all of your problems, but it may get you along the way.

Problem with Validation Control in formview ASP.NET C#

I'm having some problem with validation control in formview. I could add a validation control inside a formview control it was working fine until I tried to group them using validationgroups. Also if I dont enter a value the program still allow to add it in the database. Could someone help me point out the problem or error in my program? Here's the Insert statement I've made.
<InsertItemTemplate>
Book ID:
<asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
<asp:RequiredFieldValidator ID="RequesFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="bookidTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator" runat="server" Display="Dynamic" ControlToValidate="bookidTextBox" ValidationExpression="^([\S\s]{13,13})$" ErrorMessage="Value must be at least 13 characters long">
</asp:RegularExpressionValidator>
<br />
Title:
<asp:TextBox ID="booktitleTextBox" runat="server"
Text='<%# Bind("booktitle") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required" ControlToValidate="booktitleTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Author's lastname:
<asp:TextBox ID="lastnameTextBox" runat="server"
Text='<%# Bind("lastname") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required" ControlToValidate="lastnameTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Author's firstname:
<asp:TextBox ID="firstnameTextBox" runat="server"
Text='<%# Bind("firstname") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="* Required" ControlToValidate="firstnameTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Description:
<asp:TextBox ID="descriptionTextBox" runat="server"
Text='<%# Bind("description") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="* Required" ControlToValidate="descriptionTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Category:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="categoryDataSource" DataTextField="name"
DataValueField="categoryid" SelectedValue='<%# Bind("categoryid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="categoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [categoryid], [name] FROM [TblCategory]">
</asp:SqlDataSource>
<br />
Date added:
<asp:TextBox ID="dateaddedTextBox" runat="server"
Text='<%# Bind("dateadded") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="* Required" ControlToValidate="dateaddedTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
Status:
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="statusDataSource" DataTextField="statusname"
DataValueField="statusid" SelectedValue='<%# Bind("statusid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="statusDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [statusid], [statusname] FROM [BookStatus]">
</asp:SqlDataSource>
<br />
Quantity:
<asp:TextBox ID="quantityTextBox" runat="server"
Text='<%# Bind("quantity") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="* Required" ControlToValidate="quantityTextBox" ValidationGroup="InsertBook">
</asp:RequiredFieldValidator>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Add" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
Any help would be much appreciated ;)
Thanks in advance.
You have to set ValidationGroup="InsertBook" as you have set Validation group to your validation.
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Add" ValidationGroup="InsertBook" />

Categories

Resources