Required Field Validator hidden in asp.net Repeater - asp.net

I have reapeater in my code and trying to validate the textbox using asp.net required field validator. But validation messsage
not displaying, i opened the developer tools and found that style="visibility:hidden" added into the required field validator.
Below is my code
<asp:Repeater ID="RepeaterCategory" runat="server" DataSource='<%# this.Categories.Count==0 ? null : this.Categories %>'>
<ItemTemplate>
<div>
<asp:Label runat="server" Visible="true" Text="Category" />
<asp:PlaceHolder runat="server" Visible="true">
<asp:TextBox ID="txtCategoryID" runat="server" value="1" />
<asp:TextBox ID="txtCategoryName" runat="server" value="<%# (Container.DataItem as Category).Name %>" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="<br/>This is a required field" ControlToValidate="txtCategoryName" ValidationGroup="NewCategoryGroup"></asp:RequiredFieldValidator>
</asp:PlaceHolder>
<asp:LinkButton runat="server" ToolTip="Save" ValidationGroup="NewCategoryGroup" OnClick="SaveCategory_Click"><img src='<%# some path%>/images/save.gif' /></asp:LinkButton>
<asp:LinkButton runat="server" ToolTip="Close" OnClick="CloseCategory_Click"></asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>
Code behind file
protected void SaveCategory_Click(object o, EventArgs e)
{
Page.Validate("NewCategoryGroup");
if (!Page.IsValid)
return;
//logic
}
Can anyone suggest how to enable it?

The style="visibility:hidden" is default behavior. It changes to style="visibility: visible;" when the error message needs displaying. Therefore you probably don't have an error.
The validator is a 'RequiredFieldValidator', and since the textbox that is being validated is already filled with the value "TestCategory" there are no errors. If you just add text to the Save button (which has no ID tag) so that it becomes visible, remove the value from the txtCategoryName textbox and click the save button you will see the error message.
This works:
<asp:TextBox ID="txtCategoryName" runat="server" value="" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="<br/>This is a required field" ControlToValidate="txtCategoryName" ValidationGroup="NewCategoryGroup"></asp:RequiredFieldValidator>
<asp:LinkButton runat="server" ToolTip="Save" ValidationGroup="NewCategoryGroup" OnClick="SaveCategory_Click" ID="LinkButton1">Save Me!</asp:LinkButton>
You don't need this code
Page.Validate("NewCategoryGroup");
if (!Page.IsValid)
Another advantage is that the validators work now without a postback, this saves a roundtrip to the server.
And ALWAYS do server side validation also, but try to do the first validation without postback.
UPDATE
What you want is probably validation per item. And since your validationgroup is always the same it will fire for all textboxes. Try this:
<asp:Repeater ID="RepeaterCategory" runat="server">
<ItemTemplate>
<div>
<asp:TextBox ID="txtCategoryName" runat="server" ValidationGroup='<%# "myVal_" + Container.ItemIndex %>' Text='<%# Eval("Category") %>' />
<br />
<asp:RequiredFieldValidator runat="server" Display="Dynamic" ErrorMessage="This is a required field<br />" ControlToValidate="txtCategoryName" ValidationGroup='<%# "myVal_" + Container.ItemIndex %>'></asp:RequiredFieldValidator>
<asp:LinkButton runat="server" ValidationGroup='<%# "myVal_" + Container.ItemIndex %>' OnClick="Button1_Click" ID="LinkButton1">Save Me!</asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>

Related

Unable to get TextBox text in DataList

I have a textbox in a datalist I'm trying to access in edit mode:
<asp:DataList ID="dl1" OnEditCommand="dl1_EditCommand"
OnCancelCommand="dl1_CancelCommand" OnUpdateCommand="dl1_UpdateCommand"
runat="server">
...
<asp:TextBox ID="tbType" Width="600" runat="server" Text='<%# Eval("Type") %>' />
CodeBehind:
protected void dl1_UpdateCommand(object sender, DataListCommandEventArgs e)
{
TextBox tb = (TextBox)e.Item.FindControl("tbType");
}
My code executes, but the value of the textbox is always empty, even though I have a value in it! I don't get either my updated text or the default text - I get a null. It finds the textbox, I've even opened the inspector to view its text...
This hasn't happened before and I'm not sure what I'm doing wrong. I've never had a problem like this before...
Full disclosure - this is a datalist inside a usercontrol.
UPDATE
Showing EditItemTemplate tags as requested.
The value is "" - I get a reference to the textbox, but no value.
<EditItemTemplate>
<td><asp:LinkButton ID="lbEdit" runat="server" Text="Update" CommandName="update" CausesValidation="false" />
<br /><asp:LinkButton ID="lbCancel" runat="server" Text="Cancel" CommandName="cancel" CausesValidation="false" />
</td>
<td>
<asp:HiddenField ID="hfID" runat="server" Value='<%# Eval("Id") %>' />
<asp:TextBox ID="tbType" Width="600" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td></td>
</EditItemTemplate>

asp.Net ValidationGroup validating correctly except on Enter key

I've seen a variety of questions here that are very close to this issue but none which seem to fit this specific scenario.
Description:
I have ID and Password fields with a Log On button in the Master page. These are in the "LoginValidationGroup" and they work fine.
Now, in the Default.aspx, I have an email TextBox and submit button that are in the "NotifyMeValidation" group, and they also work, BUT not if you hit the enter key rather than the submit button. The Submit button works fine - Enter key ... not so much.
The Enter key causes the validation to occur on the LoginValidationGroup, even though the TextBox is set to CausesValidation="true", and it is in the NotifyMeValidation group.
I guarantee people are going to enter an email in that box and hit Enter. I would!!! And when they do, they're going to see a callout balloon at the top telling them the User ID is required.
What's my error here? If I need to post the actual code I can do so.
Actually, let me just go ahead and do that.
From the Default.aspx:
<asp:RequiredFieldValidator
runat="server"
ValidationGroup="NotifyMeValidation"
ID="EmailRequiredValidator"
ControlToValidate="SenderEmailTextBox"
ErrorMessage="Email is Required"
Display="None" />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
PopupPosition="Left"
ID="EmailRequiredValidatorExtender"
Width="185px"
TargetControlID="EmailRequiredValidator"
WarningIconImageUrl="/Images/warning.gif" />
<asp:Label ID="SenderEmailLabel" runat="server" ssociatedControlID="SenderEmailTextBox" EnableViewState="false" Text="Email:"></asp:Label>
<asp:TextBox ID="SenderEmailTextBox" runat="server" ValidationGroup="NotifyMeValidation" Width="350" BackColor="#cccccc" CausesValidation="true"></asp:TextBox>
<br /><br />
<asp:Button ID="SubmitButton" runat="server" ValidationGroup="NotifyMeValidation" EnableViewState="false" CssClass="submit" Text="Send" CausesValidation="true" OnClick="btnSubmit_Click" />
From the Master page:
<asp:Label CssClass="LoginHeading" ID="UserNameLabel" runat="server" AssociatedControlID="UserNameTextbox">UserName: </asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="UserNameTextbox" runat="server" ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>
<asp:Label CssClass="LoginHeading" ID="PasswordLabel" runat="server" AssociatedControlID="PasswordTextbox">Password: </asp:Label>
<asp:TextBox CssClass="LoginTextBox" ID="PasswordTextBox" runat="server" TextMode="Password" ValidationGroup="LoginValidation" CausesValidation="True"></asp:TextBox>
<asp:Button CssClass="LoginHeading" ID="LoginButton" runat="server" Text="Button" CommandName="Login" ValidationGroup="LoginValidation" CausesValidation="True" onclick="LoginButton_Click" />
And the Master page validators...
<asp:RequiredFieldValidator runat="server" ID="UIDRequired"
ValidationGroup="LoginValidation"
ControlToValidate="UserNameTextbox"
Display="None"
ErrorMessage="<b>Required Field Missing</b><br />A User ID is required." />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
ID="UIDValidationExtender"
PopupPosition="Left"
Width="185px"
TargetControlID="UIDRequired"
WarningIconImageUrl="/Images/warning.gif" />
<asp:RequiredFieldValidator runat="server" ID="PWRequired"
ValidationGroup="LoginValidation"
ControlToValidate="PasswordTextbox"
Display="None"
ErrorMessage="<b>Required Field Missing</b><br />A password is required." />
<ajaxToolkit:ValidatorCalloutExtender
runat="Server"
ID="PWValidationExtender"
PopupPosition="Left"
TargetControlID="PWRequired"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
Display="None"
ValidationGroup="LoginValidation"
ID="CustomUserExistsValidator"
ControlToValidate="UserNameTextbox"
ErrorMessage="<b>Invalid UserID!</b><br />User ID doesn't exist. Please try again.<br />"
OnServerValidate="CustomCheckUserExists"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="UserIDCalloutExtender"
TargetControlID="CustomUserExistsValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
ID="CustomPWValidator"
Display="None"
ValidationGroup="LoginValidation"
ControlToValidate="PasswordTextbox"
ErrorMessage="<b>Invalid Password!</b><br />Please try again.<br />"
OnServerValidate="CustomValidatePassword"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="PWCalloutExtender"
TargetControlID="CustomPWValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
<asp:CustomValidator
runat="server"
ID="CustomUserApprovedValidator"
Display="None"
ValidationGroup="LoginValidation"
ControlToValidate="UserNameTextbox"
ErrorMessage="<b>Approval Error!</b><br />This UserID exists, but is not yet approved.<br />"
OnServerValidate="CustomCheckUserApproved"/>
<ajaxToolkit:ValidatorCalloutExtender
runat="server"
PopupPosition="Left"
ID="UserApprovedCalloutExtender"
TargetControlID="CustomUserApprovedValidator"
Width="185px"
WarningIconImageUrl="/Images/warning.gif" />
Try adding an <asp:Panel> around each set of controls and setting the DefaultButton property to the ID of the button you want to click when the users hits Enter.
Just to explain what is happening here, the aspx's default button is being fired when you press enter on the textbox. To handle this you could you could fire some jQuery code when the enter key is clicked on the textbox, this code will then perform the click on the specific button that you require. Check this

ASP.NET panel does not update when last item gets deleted

I am sure that I am missing something really obvious here, but I just can't see it.
I have an update panel with a datalist inside it. Each item of the datalist has a delete button with which I issue the Delete command for the item.
Deletion is a two part process: I first pop up a modal dialogue from codebehind to ask for confirmation, like so:
/// <summary>
/// Manager delete command
/// </summary>
protected void dlKeywordsManager_DeleteCommand(object source, DataListCommandEventArgs e)
{
//Get the subject ID
int keywordID = (int)dlKeywordsManager.DataKeys[e.Item.ItemIndex];
//Remember the keyword ID on the modal popup
hfKeywordID.Value = keywordID.ToString();
btnConfirmationPopupOK.CommandArgument = "Delete";
lblConfirmationPopupMessage.Text = "キーワード「" + e.CommandArgument.ToString() + "」を本当に削除しますか?";
mpConfirmationPopup.Show();
dlKeywordsManager.DataBind();
udpKeywordsManager.Update();
}
This modal popup is also within the update panel so that I can get the label text values refreshed on partial postback.
When the use presses the OK button of the popup I go on to execute:
protected void btnConfirmationPopupOK_Click(object source, EventArgs e)
{
int keywordID = int.Parse(hfKeywordID.Value);
KeywordBLLOperation operationResult;
switch (((Button)source).CommandArgument)
{
case "Delete":
operationResult = keywordsAPI.DeleteKeyword(keywordID);
switch (operationResult.Result)
{
case KeywordBLLOperationResult.Deleted:
lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」を削除しました。";
break;
case KeywordBLLOperationResult.Failed:
lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」の削除に失敗しました。アドミニストレーターにお伝えください。";
break;
}
break;
}
mpNotificationPopup.Show();
dlKeywordsManager.DataBind();
udpKeywordsManager.Update();
}
I have remove a few non-essential lines here for brevity.
And here is the aspx markup to go with the code:
<asp:UpdatePanel ID="udpKeywordsManager" runat="server" Visible="true" UpdateMode="Conditional" >
<ContentTemplate>
<div class="keywordsManagerHeader">
<%--DISPLAY STATISTICS--%>
<asp:CheckBox ID="chkShowUsageStatistics" runat="server" Text="参照回数を表示する" AutoPostBack="true" OnCheckedChanged="chkShowUsageStatistics_CheckedChanged" CssClass="keywordsManagerCheckBoxes" TextAlign="Left" />
<%--DISPLAY ORDER--%>
<span class="keywordsManagerLabel" >並べ替え</span>
<asp:DropDownList ID="ddlKeywordsOrder" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlKeywordsOrder_SelectedIndexChanged" >
<asp:ListItem Text="なし" Value="None" />
<asp:ListItem Text="科目名" Value="Name" />
<asp:ListItem Text="参照回数" Value="Frequency" />
</asp:DropDownList>
<asp:RadioButtonList ID="rdlOrder" runat="server" AutoPostBack="true" RepeatLayout="Flow" RepeatDirection="Horizontal" CssClass="keywordsManagerRadioButtons" Enabled="false" >
<asp:ListItem Text="昇順" Value="Ascending" />
<asp:ListItem Text="降順" Value="Descending" />
</asp:RadioButtonList>
<%--UPDATE PROGRESS INDICATOR--%>
<span style="position: absolute;">
<asp:UpdateProgress ID="udpSubjectsManagerUpdateProgress" AssociatedUpdatePanelID="udpKeywordsManager" runat="server" DisplayAfter="500" DynamicLayout="False" >
<ProgressTemplate>
<img class="updateProgressIndicator" src="~/Library_Images/Animations/ajax_loading.gif" alt="" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
</span>
</div>
<div class="keywordsManagerContainer">
<%--SUBJECTS DATALIST--%>
<asp:DataList ID="dlKeywordsManager" runat="server" DataKeyField="Keyword_ID" DataSourceID="dsBookKeywords" RepeatDirection="Horizontal"
OnItemDataBound="dlKeywordsManager_ItemDataBound" OnDeleteCommand="dlKeywordsManager_DeleteCommand" OnUpdateCommand="dlKeywordsManager_UpdateCommand" OnPreRender="dlKeywordsManager_PreRender" >
<ItemTemplate>
<span id="KeywordInfo" class="keywordsManagerItem" runat="server">
<asp:Label ID="Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' />
<asp:Label ID="Subject_FrequencyLabel" runat="server" Text='<%# " (" + Eval("Frequency") + ")" %>' Visible="false" />
</span>
<%--HOVER MENU PANEL--%>
<asp:Panel ID="pnlKeywordContextMenu" runat="server" CssClass="keywordsManagerPopupMenuOverall">
<div class="keywordsManagerPopupMenuRow" >
<span class="keywordsManagerLabel">科目「</span>
<asp:Label ID="pnlSubjectContextMenu_Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' />
<span class="keywordsManagerLabel">」を参照している文書数:</span>
<asp:Label ID="pnlSubjectContextMenu_Subject_FrequencyLabel" runat="server" Text='<%# Eval("Frequency") %>' />
</div>
<div ID="Book_ISO_NumbersList" class="keywordsManagerBookISONumbersList" runat="server" visible='<%# (string.IsNullOrEmpty(Eval("Book_ISO_Numbers").ToString())) ? bool.Parse("false") : bool.Parse("true") %>' >
<span class="keywordsManagerLabel">文書:</span>
<asp:Label ID="Book_ISO_Numbers_Label" runat="server" Text='<%# Eval("Book_ISO_Numbers") %>' />
</div>
<div class="keywordsManagerPopupMenuSeparator"></div>
<div class="keywordsManagerPopupMenuRow" >
<asp:TextBox ID="Keyword_NameTextBox" runat="server" Text='<%# Eval("Keyword_Name") %>' CssClass="keywordsManagerPopupMenuInput" />
<asp:Button ID="btnEdit" runat="server" Text="編集" CssClass="buttonShortBottom" CommandName="Update" CausesValidation="true" CommandArgument='<%# Eval("Keyword_Name") %>' />
<asp:Button ID="btnDelete" runat="server" Text="削除" CssClass="buttonShort" CommandName="Delete" CommandArgument='<%# Eval("Keyword_Name") %>' />
</div>
</asp:Panel>
<%--HOVER MENU EXTENDER--%>
<asp:HoverMenuExtender ID="hmeKeywordContextMenu" runat="server" TargetControlID="KeywordInfo" PopupControlID="pnlKeywordContextMenu" PopDelay="100" PopupPosition="Right" HoverDelay="100" />
</ItemTemplate>
<SeparatorTemplate>
<span class="keywordsManagerItemSeparator"></span>
</SeparatorTemplate>
</asp:DataList>
</div>
<%--MODAL POPUPS--%>
<%--CONFIRMATION POPUP--%>
<asp:Panel ID="pnlConfirmationsPopup" runat="server" CssClass="modalNotificationOverall" >
<div class="modalNotificationRow">
<asp:Label ID="lblConfirmationPopupMessage" runat="server" Text="" />
</div>
<div class="modalNotificationRow">
<asp:Button ID="btnConfirmationPopupOK" runat="server" Text="はい" CssClass="buttonMediumLong" OnClick="btnConfirmationPopupOK_Click" />
<asp:Button ID="btnConfirmationPopupCancel" runat="server" Text="いいえ" CssClass="buttonMediumLong" />
</div>
<asp:HiddenField ID="hfKeywordID" runat="server" />
<asp:HiddenField ID="hfNewKeywordName" runat="server" />
</asp:Panel>
<%--NOTIFICATION POPUP--%>
<asp:Panel ID="pnlNotificationsPopup" runat="server" CssClass="modalNotificationOverall" >
<div class="modalNotificationRow">
<asp:Label ID="lnlNotificationsPopupMessage" runat="server" Text="" />
</div>
<div class="modalNotificationRow">
<asp:Button ID="btnNotificationsPopupOK" runat="server" Text="OK" CssClass="buttonMediumLong" />
</div>
</asp:Panel>
<%--MODAL POPUP ANCHORS AND MODULES--%>
<%--DELETE CONFIRMATION--%>
<asp:Label ID="lblConfirmationPopupAnchor" runat="server" Text="" />
<asp:ModalPopupExtender ID="mpConfirmationPopup" runat="server" TargetControlID="lblConfirmationPopupAnchor" PopupControlID="pnlConfirmationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnConfirmationPopupCancel" />
<asp:Label ID="lblNotificationPopupAnchor" runat="server" Text="" />
<asp:ModalPopupExtender ID="mpNotificationPopup" runat="server" TargetControlID="lblNotificationPopupAnchor" PopupControlID="pnlNotificationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnNotificationsPopupOK" />
</ContentTemplate>
There is a lot of markup in there. The structure is as follows: I have a header section with dropdownlist, radiobuttonlist etc. which allows me to specify the sorting of the data (data comes from an object datasource)
The I have the datalist with items. Each item has a hovermenuextender in which I have the buttons to issue the edit and delete comamnds.
The modal popups are also inside the update panel, but outside the datalist, so that they can be updated as required.
My problem is that this works fine as long as the item I delete is not the last item left in the Datalist. If it is the last item the last popup (mpNotificationPopup) doesn't show.
The code executes all the way through, so the lack of items must cause the upadte panel (udpKeywordsManager) not to update?
Any help as to how to get the datalist to update in this case would be most welcome.
Thanks in advance.
Answering my own question. After painfully rebuilding the whole thing I realised that I was setting the visibility of the update panel to false in the OnPreRender event of the datalist when there were no items left. This basically switched off the update panel half-way through refreshing, so the page didn't refresh when the last element was deleted.
Have sorted it by putting a panel in the update panel which contains all the elements inside it except the "no info available" label and just toggle the visibility of that. Apologies for the stupid question, I guess I was having a stupid moment when I wrote this code...
You should show us the aspx-markup as well, but maybe you've used a ModalPopupExtender inside of your UpdatePanel. Try to move the div/Panel that has the ID of the ModalPopupExtender's PopupControlID property outside of your UpdatePanel.
You only have to nest the UpdatePanel inside of the Popup-Control and not around it.
I hope following makes it clearer:
Instead of doing it this way:
<UpdatePanel>
<DataList>
</DataList>
<ModalPopupExtender>
</ModalPopupExtender>
</UpdatePanel>
You should do it this way:
<ModalPopupExtender>
<UpdatePanel>
<DataList>
</DataList>
</UpdatePanel>
<ModalPopupExtender>

Validating controls in ListView insert/edit templates

I added a RequiredFieldValidator to my InsertItemTemplate, and it seems to be working fine. The problem I am having, however, is that now I cannot do anything else in the ListView (like edit or delete items) UNLESS the required field has a value. Is there some way I can manually do the validation when the user clicks the 'Insert' button on the InsertItemTemplate, or some other little trick I can perform so the user doesn't have to first type in a value just to delete something else in the list?
Thanks
A_Nablsi,
Please provide the code for your solution to turn the Insert New validation controls off when in Edit/Update mode or turn Edit/Update validation controls off when both the Edit and Insert Rows are active at the same time. This code using your notional solution fails with a null reference to the updateButton.
LinkButton updateButton = LVTasks.EditItem.FindControl("UpdateButtonTask") as LinkButton;
updateButton.CausesValidation = false;
The solution that works is adding Validation Groups.
Include ValidationGroup="myVGEdit" with your Validator Control(s) in the EditItemTemplate and your Update button.
Include ValidationGroup="myVGInsert" with your Validator Control(s) in the InsertItemTemplate and your Insert button.
<asp:ListView ID="LVTasks" runat="server"
DataKeyNames="IDTask"
DataSourceID="LDS_LVTasks"
InsertItemPosition="FirstItem"
oniteminserting="LVTasks_ItemInserting"
onitemupdating="LVTasks_ItemUpdating"
onitemcommand="LVTasks_ItemCommand"
>
<EditItemTemplate>
<asp:TextBox ID="TaskUpdateTextBox" runat="server"
Text='<%# Bind("Task") %>'
TextMode="MultiLine" Rows="1" Font-Bold="true" Width="300px"
/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Set Task title"
ControlToValidate="TaskUpdateTextBox"
ValidationGroup="myVGUpdate"
/>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Cancel"
CausesValidation="False"
ToolTip="Cancel - Abort - No Changes"><div class="Cancel"></div></asp:LinkButton>
<asp:LinkButton ID="UpdateButtonTask" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Update"
CausesValidation="True"
ValidationGroup="myVGEdit"
ToolTip="Save Changes - Update"><div class="Update" ></div></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TaskInsertTextBox" runat="server" Text='<%# Bind("Task") %>'
TextMode="MultiLine" Rows="1" Font-Bold="true" Width="300px"
/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please Set Task title"
ControlToValidate="TaskInsertTextBox"
ValidationGroup="myVGInsert"
/>
<asp:LinkButton ID="CancelButton" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Cancel"
CausesValidation="False"><div class="Clear" ></div></asp:LinkButton>
<asp:LinkButton ID="InsertButtonTask" runat="server"
CommandArgument='<%#Eval("IDTask") %>'
CommandName="Insert"
CausesValidation="true"
ValidationGroup="myVGInsert"
><div class="Insert" ></div></asp:LinkButton>
</InsertItemTemplate>
Yes,
set the CausesValidation property to false on the controls you don't want them to trigger the validation.

Two Validation Groups in a single button without client click event

In a multigrid I am validating two controls like date and amount. It is validating correctly when I press the tabevent. When I press the save button it is not validating. I am using two validations groups and two validation summary. Then in save button Ialso tried onclientclick() function with javascript it is working fine but if I give the correct value in date and amount records, it is not saving. how to over come this.
Date
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" Text='<%# Bind("AD_REF_DATE") %>' runat="server" CausesValidation="true"
ValidationGroup="group" Width="80px" AutoPostBack="true" OnTextChanged="txtDate_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CompareValidator ID="dateValidater" runat="server" ControlToValidate="txtDate"
Operator="DataTypeCheck" Type="Date" ValidationGroup="group" EnableClientScript="true"
ErrorMessage="Please enter a valid date (mm/dd/yyyy)." SetFocusOnError="true" Display="None">*</asp:CompareValidator>
</ItemTemplate>
</asp:TemplateField>
Amount
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount" MaxLength="17" Text='<%# Bind("AD_AMOUNT") %>' CausesValidation="true"
ValidationGroup="req" runat="server" AutoPostBack="true">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:RegularExpressionValidator ID="regVal1" runat="server" ControlToValidate="txtAmount"
ErrorMessage="Format(13int,5deci)" ValidationExpression="^[1-9]\d{0,12}(\.\d{1,2})?%?$"
ValidationGroup="req" Display="None" EnableClientScript="true" SetFocusOnError="true">
</asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
validations summary:
<asp:ValidationSummary ID="ValidationSummary3" runat="server" ValidationGroup="req"
HeaderText="Amount:Invalid Format" DisplayMode="BulletList" ShowMessageBox="true"
ShowSummary="false" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="group"
HeaderText="Date:Invalid Format" DisplayMode="BulletList" ShowMessageBox="true"
ShowSummary="false" />
button save:
<asp:Button ID="ButtonSave" runat="server" CssClass="button" CausesValidation="true" Text="<%$Resources:TJFAS501, ButtonSave %>"
OnClick="ButtonSave_Click" TabIndex="6" />
How to validate this in the button save also two popup box should be shown?
You might want to try firing the validate function for both groups manually via the button's OnClientClick since you have two validation groups you need to validate against. Currently your validation is not firing because you do not have any ValidationGroup assigned to your button so it is just looking for validators with no ValidationGroup defined (yours groups are: group and req).
You can call Page_ClientValidate() via javascript to fire off the validation checks manually (be sure to set CauseValidation on your button to false) and it has an optional parameter that takes the validation group.
<asp:Button ID="yourButton" runat="server" OnClick="ButtonSave_Click"
CausesValidation="false" TabIndex="6"
OnClientClick="return (Page_ClientValidate('group') && Page_ClientValidate('req'));" />
You can read more about Page_ClientValidate on MSDN.
It would be easier to just have one validation group for each action (eg. your button) but I assume you need two groups for some reason.
Try this..
<script type="text/javascript">
function Validate() {
var isValid = false;
isValid = Page_ClientValidate('Group1');
if (isValid) {
isValid = Page_ClientValidate('Group2');
}
return isValid;
}
</script>

Resources