I have a repeater control rptbrand in which one textbox txtMultiBrand is there and after each repeating time when i click btnAddBrand button i want validation for unique entries in textbox, here is my aspx code
<table width="100%">
<asp:Repeater ID="rptBrand" runat="server" OnItemDataBound="rptBrandDetail_ItemDataBound">
<ItemTemplate>
<tr>
<td align="right" `enter code here`width="150">
Brand<asp:Label ID="lblBrandNum" runat="server"></asp:Label>
<span class="msgred">*</span> :
</td>
<td align="left">
<table width="100%">
<tr>
<td align="left" width="20%">
<asp:TextBox ID="txtMultiBrand" CssClass="imageSearch" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ValidationGroup="VGrpMultiSave"
ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ValidationGroup="VGrpSave"
ControlToValidate="txtMultiBrand" ErrorMessage="Brand Required" Display="none"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
<td align="left">
<asp:ImageButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="CmdDelete"
CommandArgument='<%# Eval("SrNo") %>' ToolTip="Delete" ImageUrl="images/b_drop.png"
OnCommand="rptBrand_Command" Width="16" Height="16" OnClientClick="javascript:return confirm('Are you sure you want to remove brand?')" />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td align="right" width="150">
</td>
<td>
<asp:Button ID="btnAddBrand" runat="server" Text="Add more" ValidationGroup="VGrpMultiSave"
OnClick="btnAddBrand_Click" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" ValidationGroup="VGrpMultiSave" />
</td>
</tr>
</table>
Using jQuery:
IT IS WORKING
Check the below link:
http://jsfiddle.net/NtF7h/
$(function () {
$("#<%=btnAddBrand.ClientID%>").on("click", function (event) {
var valueArray = new Array(); ;
$("input[id*='txtMultiBrand']").each(function (index) {
if ($.inArray($(this).val(), valueArray) == -1) {
valueArray[index] = $(this).val();
}
else {
alert("Duplicate Entry Found.");
event.preventDefault();
return false;
}
});
});
});
Related
I have a List of Client Displayed in Repeater. I have a Details Button in Repeater which displays the Details of Client when Clicked. For Sample now just added 'ClientName' only. *When i Click on 'Details' LinkButton in Repeater it Displays the Details of Selected Row. But, this causes FullPage Post Back! Which i want to Prevent. Just i want to Update the Panel which displays the Details when row is selected from Repeater*.
In .aspx page:
<script>
function ShowPopUp() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "block";
}
function ClosePopup() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "none";
}
</script>
<asp:Repeater ID="RepDetails" runat="server" OnItemCommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table class="tabl">
<tr style="background-color: #808080; color: White">
<td class="lblCenter">
<asp:Label ID="Label4" runat="server" Text="City" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label3" runat="server" Text="Age" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label1" runat="server" Text="Gender" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label5" runat="server" Text="Details" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="<%# Container.ItemIndex % 2 == 0 ? "rowEven" : "rowOdd" %>">
<td class="lblCenter">
<asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblAge" runat="server" Text='<%#Eval("Age") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblGen" runat="server" Text='<%#Eval("Gender") %>' CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:LinkButton ID="lblDetails" runat="server" CommandName="Display"
CommandArgument='<%#Eval("ID") %>'>Details</asp:LinkButton></td>
<asp:Label ID="rlblClientname" runat="server" Text='<%#Eval("Client") %>' Visible="false"></asp:Label>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div id="popup" style="display: none">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<table width="80%" align="center">
<tr>
<td> </td>
<td width="30%"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="Label15" runat="server" CssClass="lbl" Text="Client Code"></asp:Label>
</td>
<td>
<asp:Label ID="lblClientName" runat="server" CssClass="lbl"></asp:Label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input id="Button2" type="button" value="Close" onclick="ClosePopup();" class="but" /> </td>
</tr>
</table>
</ContentTemplate>
<%-- <Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="RepDetails_ItemCommand" />
</Triggers>--%>
</asp:UpdatePanel>
</div>
In Repeater Item Command:
protected void RepDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Display")
{
LinkButton lblDetails = (LinkButton)e.Item.FindControl("lblDetails");
Label rlblClientname = (Label)e.Item.FindControl("rlblClientname");
if (lblDetails != null && e.CommandArgument != null)
{
string val = e.CommandArgument.ToString();
if (rlblClientname != null && rlblClientname.Text != string.Empty)
{
lblClientName.Text = rlblClientname.Text;
}
string scrpt = "ShowPopUp();";
Page.ClientScript.RegisterStartupScript(this.GetType(), "s", scrpt, true);
}
}
}
This causes Full Page Post Back Which i want to Prevent.Onclick of Repeater row the details must be displayed with AsynPostBack. When adding Trigger Event to 'popup' div then it say control could not be found
Help Appreciated!
Thanks!
You have one of two Options:
1) Uncomment this code and change EventName="RepDetails_ItemCommand" to EventName="ItemCommand"
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="ItemCommand" />
</Triggers>
2) Put the Repeater in the <ContentTemplate> of the UpdatePanel
I have a list view and i want to add a header row in it which will come when the listview has data or not. in each and every condition i want it there. I have used LayOut Template to do so but its showing the Header row only if the listview has data.Then i tried EmptydataTemplate, Its showing the header row but now the button in it is not working.
My code is
<asp:UpdatePanel ID="upViewSchedule" runat="server">
<ContentTemplate>
<asp:ListView ID="lstuser" runat="server" ItemPlaceholderID="trItem" DataKeyNames="id"
OnItemDataBound="lstuser_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "OddRowColor" : "EvenRowColor" %>'>
<td align="left" width="138px">
<asp:DropDownList ID="drpname" runat="server" Width="120px">
</asp:DropDownList>
<asp:Label ID="lblCreatedBY" Text='<%# Eval("CreatedBy") %>' runat="server" Visible="false"></asp:Label>
<asp:Label ID="lblId" runat="server" Visible="false"></asp:Label>
<ajaxCtrl:CascadingDropDown ID="casddrpContacts" runat="server" TargetControlID="drpname"
Category="name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="Getuser">
</ajaxCtrl:CascadingDropDown>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("salary") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("address") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" class="last">
<asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew2/images/update.png"
CommandArgument='<%# Eval("id") %>' OnClick="imgBtnEdit_Click" ToolTip="Update user" />
<asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete this user ?');"
ToolTip="Delete user" OnClick="imgBtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
my Code behind code is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BIndAddress();
// BindRoleDrop();
drpAddress.Items.Insert(0, new ListItem("Select Area", ""));
drpRoom.Items.Insert(0, new ListItem("Select Room", ""));
ViewState["sortCol"] = "tblUser.id";
ViewState["sortDir"] = "Desc";
ViewState["nmbr"] = 1;
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), 7999);
}
else
{
lblMessage.Visible = false;
}
}
And one thing more please let me know how can i apply validations on these.
I did some testing locally. I found that if I have a button in the EmptyDataTemplate it's OnClick event will fire as expected as long as you do not modify the state of the ListView before the event fires.
I'm guessing therefore that you have some code that modifies the state (re-binds it for instance) of the ListView which runs before the imgBtnHdrAdd_Click event handler for the button in question.
The Page_Load method would have been the primary suspect, but based on your code it is properly checking for !IsPostBack.
I'm assuming that it is the call to BindData that is used for setting databinding the ListView. Look for other places in you code behind where that method is called and verify that none of those places are being run before the event handler for the button.
I have listview and i need to bind the dropdown list in the list view to ListItemCollection which will be built using a function BindPages().
When I clicked on the AddNew Link I am not able to bind the dropdown.
<asp:ListView DataKeyNames="Menuid" OnItemCommand="lvParentMenus_ItemCommand" OnSorting="lvParentMenus_Sorting"
OnDataBound="lvParentMenus_DataBound" DataSourceID="SqlDataSource1" ID="lvParentMenus"
runat="server">
<LayoutTemplate>
<table border="0" id="listview" width="100%" class="grid" cellpadding="0" cellspacing="0">
<thead>
<tr class="listingheader ">
<td width="10%" style="text-align: center; !important">
<input type="checkbox" name="checkbox" id="headercheck" />
</td>
<td id="thsno" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Sno"
Text="Sno" />
</td>
<td id="thmenutext" runat="server">
<asp:LinkButton runat="server" ID="LinkButton2" Text="Menu Text" CommandName="Sort"
CommandArgument="MenuText" />
</td>
<td id="thmenuurl" runat="server">
<asp:LinkButton runat="server" ID="LinkButton3" Text="Menu Url" CommandName="Sort"
CommandArgument="MenuUrl" />
</td>
<td id="thlevel" runat="server">
<asp:LinkButton runat="server" ID="LinkButton4" Text="Level of Display" CommandName="Sort"
CommandArgument="level" />
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody>
<tr runat="server" id="itemPlaceholder">
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" align="center">
<asp:Label ID="lblMessage" Text="dfdfdfd" runat="server"></asp:Label>
</td>
<td align="right">
<asp:LinkButton Text="Add New" ID="lnkNew" CommandName="FillDropDown" runat="server"
Font-Bold="true" OnClick="AddNew"></asp:LinkButton>
</td>
</tr>
</tfoot>
</table>
<ItemTemplate>
<tr class='<%# Container.DataItemIndex % 2 == 0 ? "lrow1" : "lrow1 altrow" %>'>
<td class="col1" align="center">
<asp:CheckBox runat="server" ID="chkitem"></asp:CheckBox>
</td>
<td class="lrow1">
<%# Eval("Sno")%>
<asp:HiddenField ID="hdnStoreID" runat="server" Value='<%# Eval("MenuId") %>' />
</td>
<td>
<%# Eval("MenuText")%>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSource='<%#BindLevel(6)%>' SelectedValue='<%# Eval("level")%>'>
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
|
<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure to delete the current item');">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="lrow1">
<td class="col1" align="center">
</td>
<td class="lrow1">
</td>
<td class="lrow1">
<asp:TextBox ID="txtMenuText" runat="server" Width="80px" Text='<%# Eval("MenuText")%>'
CssClass="inputbox" ValidationGroup="InsertFields" />
<asp:RequiredFieldValidator ID="reqValidCity" ControlToValidate="txtMenuText" runat="server"
ErrorMessage="City Name is required." Display="Dynamic" ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValidCity" runat="server" ErrorMessage="Please Enter Alphabets only."
Display="Dynamic" ValidationGroup="g1" ControlToValidate="txtMenuText" ValidationExpression="^[a-zA-Z0-9\s]{2,1000}"></asp:RegularExpressionValidator>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSourceID="sdsLevel" DataValueField="level"
DataTextField="level">
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkinsert" runat="server" OnClick="lnkinsert_Click" ValidationGroup="InsertFields"> Insert</asp:LinkButton>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="usp_getParentMenus"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlRoles" Name="intRoleid" PropertyName="Text" DefaultValue="1"
ConvertEmptyStringToNull="true" Direction="Input" />
</SelectParameters>
</asp:SqlDataSource>
and here is the method BindPAges()
protected ListItemCollection BindPages()
{
string sDir = Request.PhysicalApplicationPath;
if (FirstCount == 0)
DirSearch(sDir);
return collection;
}
When I tried to find the ddlPageList in the AddNew() method it is throwing error "Object referenc not set "
AddNEw() Method:
` protected void AddNew(object sender, EventArgs e)
{
lvParentMenus.InsertItemPosition = InsertItemPosition.FirstItem;
lvParentMenus.FindControl("lnkNew").Visible = false;
lvParentMenus.EditIndex = -1;
sdsLevel.ConnectionString = DBConnectionString.ConnectionString;
Parameter a = new Parameter("intRoleid", DbType.Int32);
a.DefaultValue = ddlRoles.SelectedValue.ToString();
sdsLevel.SelectParameters.Add(a);
sdsLevel.SelectCommand = "usp_getParentMenus";
DropDownList ddlpages = (DropDownList)lvParentMenus.FindControl("ddlPagesList");
string sDir = Request.PhysicalApplicationPath;
DirSearch(sDir);
ddlpages.DataSource = collection;
ddlpages.DataBind();
}
Need urgently.
Thanks.
Please try
DropDownList ddlpages = (DropDownList)lvParentMenus.Items[0].FindControl("ddlPagesList");
Have you tried to use runat=server property in TABLE in Listview?
I have few text boxes which has required field validation. In the same page there is a back button and next button. When i click in the back button the validations are working, when i click on the next button validations are not working (means the form is moving to the next page)
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="RequestorForm.aspx.vb"
Inherits="WebApplication1.RequestorForm" %>
<!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 id="Head1" runat="server">
<title>Requestor Form</title>
<link rel="stylesheet" type="text/css" href="homepage2005.css">
<script language="javascript" type="text/javascript">
//Call Server Event on User id onblur()
function CallClientEvent() {
__doPostBack("txt_view1_userID_TextChanged", "");
}
function CheckValidation() {
Page_ClientValidate();
if (Page_IsValid) {
if (CheckRoleValidation()) {
if ('<%=strRoleType%>' == 'chkBx_Store_wu') {
return CheckTeamViewerDep();
}
}
else {
return false;
}
}
}
function CheckTeamViewerDep() {
var ctl = document.getElementById('chkbx_teamLeadStockRoom');
if (ctl.disabled) {
return true;
}
var tDiv = document.getElementById('chkDepGroup');
var chkitm = tDiv.getElementsByTagName("input");
for (var i = 0; i < chkitm.length; i++) {
if (chkitm[i].checked) {
return true;
}
}
var ctlvalidate = document.getElementById('span_chkDepGroup');
ctlvalidate.innerHTML = 'Please select Dep';
return false;
}
function CheckRoleValidation() {
//var cblItm = '<%=gvRoleDep%>';
var tDiv = document.getElementById('gvRoleDep');
var chkitm = tDiv.getElementsByTagName("input");
var flag = false;
var chkItemCount = 0;
for (var i = 0; i < chkitm.length; i++) {
if (chkitm[i].checked) {
chkItemCount++;
flag = true;
}
}
var ctlvalidate = document.getElementById('lbl_chkBx_store_wu');
if (!flag) {
ctlvalidate.innerHTML = 'Please select Role(s)';
return false;
}
if (chkItemCount > 5) {
ctlvalidate.innerHTML = 'Maximum of 5 Role(s) only can be checked';
return false;
}
}
function ValidateDropDown() {
Page_ClientValidate();
flag = 1;
objTOR = document.getElementById('ddl_view0_typeOfRequest');
objWUL = document.getElementById('ddl_view0_wuLevel');
if (Page_IsValid) {
//alert(objTOR.selectedIndex);
TOR = document.getElementById('span_ddl_view0_typeOfRequest');
WUL = document.getElementById('span_ddl_view0_wuLevel');
if (objTOR.selectedIndex == 0) {
//alert('Select a value:');
TOR.innerHTML = "*Please select a Type of Request";
flag = 0;
}
else
TOR.innerHTML = " ";
// if (objWUL.selectedIndex == 0) {
// WUL.innerHTML = "*Please select a W A";
// flag = 0;
// }
// else
// WUL.innerHTML = " ";
if (flag == 0)
return false;
return true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 10px">
<asp:MultiView runat="server" ID="mvRequestorForm" ActiveViewIndex="0">
<asp:View runat="server" ID="view_0">
<h1 class="blue">
<asp:Label ID="lbl_viewTitle0" runat="server" Text="Label"></asp:Label>
</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="tabRow" width="150">
<asp:Label ID="lbl_view0_firstName" runat="server" Text="Firstname "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_firstName" runat="server" AutoCompleteType="FirstName"
CssClass="text_box_3" TabIndex="1"></asp:TextBox>
<asp:Label ID="Label5" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_FirstName" runat="server"
ControlToValidate="txt_firstName" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_surname" runat="server" Text="Surname"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSurName" runat="server" AutoCompleteType="LastName"
CssClass="text_box_3" TabIndex="3"></asp:TextBox>
<asp:Label ID="Label6" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_Surname" runat="server"
ControlToValidate="txtSurName" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_ContactNum" runat="server" Text="Contact number"></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_contactNum" runat="server"
AutoCompleteType="BusinessPhone" CssClass="text_box_3" TabIndex="3"></asp:TextBox>
<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_ContactNumber" runat="server"
ControlToValidate="txt_contactNum" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txt_contactNum" ErrorMessage="Enter a numeric value"
MaximumValue="99999999999999" MinimumValue="0"></asp:RangeValidator>
</td>
</tr>
</table>
<hr class="blue" />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="tabRow" width="150">
<asp:Label ID="lbl_view0_typeOfRequest" runat="server" Text="Type of request"></asp:Label>
</td>
<td width="500">
<asp:DropDownList ID="ddl_view0_typeOfRequest" runat="server"
CssClass="drop_down_t" TabIndex="4">
<asp:ListItem Value="-1">Please select...</asp:ListItem>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Update</asp:ListItem>
<asp:ListItem>Delete</asp:ListItem>
</asp:DropDownList>
<span ID="span_ddl_view0_typeOfRequest" class="errorText"></span>
</td>
<td>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_wuLevel" runat="server" Text="W A"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddl_view0_wuLevel" runat="server"
CssClass="drop_down_t" TabIndex="5">
<asp:ListItem Selected="True" Value="3">Store</asp:ListItem>
</asp:DropDownList>
<span ID="span_ddl_view0_wuLevel" class="errorText">
</span>
</td>
<td>
</td>
</tr>
<tr> <td> </td> <td></td><td> </td></tr>
</table>
<asp:Label ID="lblCaption1" runat="server"
Text="* Represents fields that needs to be filled mandatory"
Font-Size="XX-Small" ForeColor="#FF3300"></asp:Label>
<br />
<hr />
<asp:Button ID="btn_View0_Next" runat="server"
OnClientClick="return ValidateDropDown();" Text="Next"
ValidationGroup="Form1" />
<br />
</asp:View>
<asp:View runat="server" ID="view_1">
<asp:ScriptManager ID="scrMgr" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td><asp:Label ID="lblException" CssClass="errorText" runat="server"></asp:Label></td>
</tr>
</table>
<h1 class="blue">
<asp:Label ID="lbl_viewTitle1" runat="server" Text="Label"></asp:Label>
</h1>
<table border="0">
<tr>
<td>
<table border="1" style="border-color:Green; border-width:thin;" width="100%">
<tr>
<td valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr id="trUserDetail" runat="server">
<td class="tabRow">
<asp:Label ID="lbl_view1_userID" runat="server"
Text="User ID "></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_view1_userID" runat="server" Text="" onblur="CallClientEvent()" AutoPostBack="true" >
</asp:TextBox>
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="*"></asp:Label>
<div class="smallText" nowrap> (This would be the ID you would normally log on with.)</div>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txt_view1_userID" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="150" class="tabRow">
<asp:Label ID="lbl_panview3_label2" runat="server" Text="St Nu "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_panview3_input2" runat="server" MaxLength="4">0000</asp:TextBox>
<asp:Label ID="Label8" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="txt_panview3_input2"
ErrorMessage="Please enter a valid 4-digit St Nu " MaximumValue="999999"
MinimumValue="1" Type="Integer" ValidationGroup="Form2"></asp:RangeValidator>
</td>
</tr>
<tr>
<td colspan="3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txt_panview3_input2" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lblEmployeeNumber" runat="server"
Text="Employee Number "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmployeeNumber" runat="server">
</asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtEmployeeNumber" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="150" class="tabRow">
<asp:Label ID="lbl_view1_firstName" runat="server" Text="Firstname "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_view1_firstname" runat="server"></asp:TextBox>
<asp:Label ID="Label9" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_view1_firstname" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view1_surname" runat="server" Text="Surname "></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_view1_surname" runat="server"></asp:TextBox>
<asp:Label ID="Label10" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txt_view1_surname" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:Label ID="lblCaption2" runat="server"
Text="* Represents fields that needs to be filled mandatory"
Font-Size="XX-Small" ForeColor="Red"></asp:Label>
<hr />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<asp:Panel ID="panelHO" runat="server">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" width="200">
<asp:Label ID="lbl_HO_wu" runat="server" CssClass="boldLabel"
Text="Role" />
</td>
<td align="left" width="200">
<asp:Label ID="lbl_panview1_label1" runat="server" CssClass="boldLabel"
Text="Dep" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td align="left" valign="top">
<asp:CheckBoxList ID="chkBx_HO_wu" runat="server" />
<span id="lbl_chkBx_HO_wu" class="errorText"></span>
</td>
<td align="left" valign="top">
<asp:DropDownList ID="ddl_panview1_ddinput1" runat="server">
<asp:ListItem>Avebury</asp:ListItem>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="panelRegion" runat="server">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="30%">
<asp:Label ID="lbl_Region_wu" runat="server" CssClass="boldLabel"
Text="Role" />
</td>
<td width="30%">
<asp:Label ID="lbl_panview2_label1" runat="server" CssClass="boldLabel"
Text="Region" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td valign="top">
<asp:CheckBoxList ID="chkBx_Region_wu" runat="server" />
<span id="lbl_chkBx_Region_wu" class="errorText"></span>
</td>
<td valign="top">
<asp:DropDownList ID="ddl_panview2_ddinput1" runat="server">
<asp:ListItem>Northern (NORTHERN)</asp:ListItem>
<asp:ListItem>Central (CENTRAL)</asp:ListItem>
<asp:ListItem>Southern (SOUTHERN)</asp:ListItem>
Check whether the call to the ValidateDropDown method is in the generated HTML. Use Firebug to debug the JavaScript.
I have few text boxes which has required field validation. In the same page there is a back button and next button. When i click in the back button the validations are working, when i click on the next button validations are not working (means the form is moving to the next page)
Please help me to rectify
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="RequestorForm.aspx.vb"
Inherits="WebApplication1.RequestorForm" %>
<!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 id="Head1" runat="server">
<title>Requestor Form</title>
<link rel="stylesheet" type="text/css" href="homepage2005.css">
<script language="javascript" type="text/javascript">
//Call Server Event on User id onblur()
function CallClientEvent() {
__doPostBack("txt_view1_userID_TextChanged", "");
}
function CheckValidation() {
Page_ClientValidate();
if (Page_IsValid) {
if (CheckRoleValidation()) {
if ('<%=strRoleType%>' == 'chkBx_Store_wu') {
return CheckTeamViewerDep();
}
}
else {
return false;
}
}
}
function CheckTeamViewerDep() {
var ctl = document.getElementById('chkbx_teamLeadStockRoom');
if (ctl.disabled) {
return true;
}
var tDiv = document.getElementById('chkDepGroup');
var chkitm = tDiv.getElementsByTagName("input");
for (var i = 0; i < chkitm.length; i++) {
if (chkitm[i].checked) {
return true;
}
}
var ctlvalidate = document.getElementById('span_chkDepGroup');
ctlvalidate.innerHTML = 'Please select Dep';
return false;
}
function CheckRoleValidation() {
//var cblItm = '<%=gvRoleDep%>';
var tDiv = document.getElementById('gvRoleDep');
var chkitm = tDiv.getElementsByTagName("input");
var flag = false;
var chkItemCount = 0;
for (var i = 0; i < chkitm.length; i++) {
if (chkitm[i].checked) {
chkItemCount++;
flag = true;
}
}
var ctlvalidate = document.getElementById('lbl_chkBx_store_wu');
if (!flag) {
ctlvalidate.innerHTML = 'Please select Role(s)';
return false;
}
if (chkItemCount > 5) {
ctlvalidate.innerHTML = 'Maximum of 5 Role(s) only can be checked';
return false;
}
}
function ValidateDropDown() {
Page_ClientValidate();
flag = 1;
objTOR = document.getElementById('ddl_view0_typeOfRequest');
objWUL = document.getElementById('ddl_view0_wuLevel');
if (Page_IsValid) {
//alert(objTOR.selectedIndex);
TOR = document.getElementById('span_ddl_view0_typeOfRequest');
WUL = document.getElementById('span_ddl_view0_wuLevel');
if (objTOR.selectedIndex == 0) {
//alert('Select a value:');
TOR.innerHTML = "*Please select a Type of Request";
flag = 0;
}
else
TOR.innerHTML = " ";
// if (objWUL.selectedIndex == 0) {
// WUL.innerHTML = "*Please select a W A";
// flag = 0;
// }
// else
// WUL.innerHTML = " ";
if (flag == 0)
return false;
return true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 10px">
<asp:MultiView runat="server" ID="mvRequestorForm" ActiveViewIndex="0">
<asp:View runat="server" ID="view_0">
<h1 class="blue">
<asp:Label ID="lbl_viewTitle0" runat="server" Text="Label"></asp:Label>
</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="tabRow" width="150">
<asp:Label ID="lbl_view0_firstName" runat="server" Text="Firstname "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_firstName" runat="server" AutoCompleteType="FirstName"
CssClass="text_box_3" TabIndex="1"></asp:TextBox>
<asp:Label ID="Label5" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_FirstName" runat="server"
ControlToValidate="txt_firstName" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_surname" runat="server" Text="Surname"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSurName" runat="server" AutoCompleteType="LastName"
CssClass="text_box_3" TabIndex="3"></asp:TextBox>
<asp:Label ID="Label6" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_Surname" runat="server"
ControlToValidate="txtSurName" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_ContactNum" runat="server" Text="Contact number"></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_contactNum" runat="server"
AutoCompleteType="BusinessPhone" CssClass="text_box_3" TabIndex="3"></asp:TextBox>
<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="Validator_ContactNumber" runat="server"
ControlToValidate="txt_contactNum" ErrorMessage="* Required field"
ValidationGroup="Form1"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txt_contactNum" ErrorMessage="Enter a numeric value"
MaximumValue="99999999999999" MinimumValue="0"></asp:RangeValidator>
</td>
</tr>
</table>
<hr class="blue" />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="tabRow" width="150">
<asp:Label ID="lbl_view0_typeOfRequest" runat="server" Text="Type of request"></asp:Label>
</td>
<td width="500">
<asp:DropDownList ID="ddl_view0_typeOfRequest" runat="server"
CssClass="drop_down_t" TabIndex="4">
<asp:ListItem Value="-1">Please select...</asp:ListItem>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Update</asp:ListItem>
<asp:ListItem>Delete</asp:ListItem>
</asp:DropDownList>
<span ID="span_ddl_view0_typeOfRequest" class="errorText"></span>
</td>
<td>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view0_wuLevel" runat="server" Text="W A"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddl_view0_wuLevel" runat="server"
CssClass="drop_down_t" TabIndex="5">
<asp:ListItem Selected="True" Value="3">Store</asp:ListItem>
</asp:DropDownList>
<span ID="span_ddl_view0_wuLevel" class="errorText">
</span>
</td>
<td>
</td>
</tr>
<tr> <td> </td> <td></td><td> </td></tr>
</table>
<asp:Label ID="lblCaption1" runat="server"
Text="* Represents fields that needs to be filled mandatory"
Font-Size="XX-Small" ForeColor="#FF3300"></asp:Label>
<br />
<hr />
<asp:Button ID="btn_View0_Next" runat="server"
OnClientClick="return ValidateDropDown();" Text="Next"
ValidationGroup="Form1" />
<br />
</asp:View>
<asp:View runat="server" ID="view_1">
<asp:ScriptManager ID="scrMgr" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td><asp:Label ID="lblException" CssClass="errorText" runat="server"></asp:Label></td>
</tr>
</table>
<h1 class="blue">
<asp:Label ID="lbl_viewTitle1" runat="server" Text="Label"></asp:Label>
</h1>
<table border="0">
<tr>
<td>
<table border="1" style="border-color:Green; border-width:thin;" width="100%">
<tr>
<td valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr id="trUserDetail" runat="server">
<td class="tabRow">
<asp:Label ID="lbl_view1_userID" runat="server"
Text="User ID "></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_view1_userID" runat="server" Text="" onblur="CallClientEvent()" AutoPostBack="true" >
</asp:TextBox>
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="*"></asp:Label>
<div class="smallText" nowrap> (This would be the ID you would normally log on with.)</div>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txt_view1_userID" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="150" class="tabRow">
<asp:Label ID="lbl_panview3_label2" runat="server" Text="St Nu "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_panview3_input2" runat="server" MaxLength="4">0000</asp:TextBox>
<asp:Label ID="Label8" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="txt_panview3_input2"
ErrorMessage="Please enter a valid 4-digit St Nu " MaximumValue="999999"
MinimumValue="1" Type="Integer" ValidationGroup="Form2"></asp:RangeValidator>
</td>
</tr>
<tr>
<td colspan="3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txt_panview3_input2" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lblEmployeeNumber" runat="server"
Text="Employee Number "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmployeeNumber" runat="server">
</asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtEmployeeNumber" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="150" class="tabRow">
<asp:Label ID="lbl_view1_firstName" runat="server" Text="Firstname "></asp:Label>
</td>
<td width="200">
<asp:TextBox ID="txt_view1_firstname" runat="server"></asp:TextBox>
<asp:Label ID="Label9" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_view1_firstname" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="tabRow">
<asp:Label ID="lbl_view1_surname" runat="server" Text="Surname "></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_view1_surname" runat="server"></asp:TextBox>
<asp:Label ID="Label10" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txt_view1_surname" ErrorMessage="* Required field"
ValidationGroup="Form2"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<asp:Label ID="lblCaption2" runat="server"
Text="* Represents fields that needs to be filled mandatory"
Font-Size="XX-Small" ForeColor="Red"></asp:Label>
<hr />
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<asp:Panel ID="panelHO" runat="server">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" width="200">
<asp:Label ID="lbl_HO_wu" runat="server" CssClass="boldLabel"
Text="Role" />
</td>
<td align="left" width="200">
<asp:Label ID="lbl_panview1_label1" runat="server" CssClass="boldLabel"
Text="Dep" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td align="left" valign="top">
<asp:CheckBoxList ID="chkBx_HO_wu" runat="server" />
<span id="lbl_chkBx_HO_wu" class="errorText"></span>
</td>
<td align="left" valign="top">
<asp:DropDownList ID="ddl_panview1_ddinput1" runat="server">
<asp:ListItem>Avebury</asp:ListItem>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="panelRegion" runat="server">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="30%">
<asp:Label ID="lbl_Region_wu" runat="server" CssClass="boldLabel"
Text="Role" />
</td>
<td width="30%">
<asp:Label ID="lbl_panview2_label1" runat="server" CssClass="boldLabel"
Text="Region" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td valign="top">
<asp:CheckBoxList ID="chkBx_Region_wu" runat="server" />
<span id="lbl_chkBx_Region_wu" class="errorText"></span>
</td>
<td valign="top">
<asp:DropDownList ID="ddl_panview2_ddinput1" runat="server">
<asp:ListItem>Northern (NORTHERN)</asp:ListItem>
<asp:ListItem>Central (CENTRAL)</asp:ListItem>
<asp:ListItem>Southern (SOUTHERN)</asp:ListItem>
Two possibilities spring immediately to mind:
The "next" button's CausesValidation property is set to false.
The "next" button is in a different ValidationGroup to the other controls.
Make sure the CausesValidation property is set to true on the buttons that you want validation to occur when clicked.
<asp:Button CausesValidation="TRUE" runat="server" />