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" />
Related
HoverMenuExtender only works after postback in gridview. Weird behavior.
<asp:TemplateField>
<HeaderStyle CssClass="CenterAligner" />
<ItemTemplate>
<asp:Image ID="imgNotes" runat="server" ImageUrl="Images/information.png" Style="position: relative" />
<asp:Panel ID="pnlNotes" runat="server" BackColor="GhostWhite" BorderColor="Black" BorderStyle="Solid" BorderWidth="1" Width="500px" Visible="true">
<div style="position: relative">
<div style="padding: 10px; margin: 10px; text-align: justify">
<asp:Label ID="lblCreditInfo" runat="server" Font-Size="9pt" ForeColor="Black"></asp:Label>
<asp:Label ID="lblCreditWebSite" runat="server" Font-Size="9pt" Text='<%# Bind("CreditWebSite") %>' Visible="false"></asp:Label>
<asp:Label ID="lblCreditUserName" runat="server" Font-Size="9pt" Text='<%# Bind("CreditUserName") %>' Visible="false"></asp:Label>
<asp:Label ID="lblCreditPassword" runat="server" Font-Size="9pt" Text='<%# Bind("CreditPassword") %>' Visible="false"></asp:Label>
</div>
<br />
</div>
</asp:Panel>
<ajaxToolkit:HoverMenuExtender ID="hmeNotes" runat="server" PopupControlID="pnlNotes" PopupPosition="left" TargetControlID="imgNotes">
</ajaxToolkit:HoverMenuExtender>
</ItemTemplate>
<ItemStyle HorizontalAlign="center" />
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
Before Postback After Postback
I was missing the panel for the balloon extender that was also on the page.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a GridView in which I have textboxes with calendar extendar. I am facing a strange problem.. The calendar extender works ok for the first row of the GridView but it does not work.
ASPX CODE is as below:(sorry, I know it's a long code.)
<asp:TabContainer AutoPostBack="false" ID="TabContainer_Main" Height="270px" runat="server">
<asp:TabPanel ID="TabPanel__TravelLine" runat="server" HeaderText="Travel Line">
<ContentTemplate>
<div id="div_TravelLine">
<asp:UpdatePanel ID="upPanel_TravelLine" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel_TravelLine" runat="server">
<asp:GridView ID="grvTravelLine" CssClass="tabledata" runat="server" ShowFooter="True"
AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" Width="100%" OnRowDataBound="grvTravelLine_RowDataBound">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="From City">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("From_City") %>' onkeypress="return Alpha(event);"
ID="txtFrmCity_TravelLine" Width="70px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To City">
<ItemTemplate>
<asp:TextBox ID="txtToCity_TravelLine" Text='<%# Eval("To_City") %>' onkeypress="return Alpha(event);"
MaxLength="50" Width="70px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Travel Mode">
<ItemTemplate>
<asp:DropDownList ID="ddlTravelMode_TravelLine" Width="100px" CssClass="drpdown"
runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Travel Date">
<ItemTemplate>
<asp:TextBox ID="txtTravelDt_TravelLine" Text='<%# Eval("TravelDt") %>' Width="70px"
runat="server" ClientIDMode="Static" CssClass="FormText"></asp:TextBox>
<asp:CalendarExtender
ID="Cal_txtTravelDt" CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd"
TargetControlID="txtTravelDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Booking Date">
<ItemTemplate>
<asp:TextBox ID="txtBookingDt_TravelLine" Text='<%# Eval("BookingDt") %>' runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtBookingDt"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtBookingDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Arrival Date">
<ItemTemplate>
<asp:TextBox ID="txtArrivalDt_TravelLine" Text='<%# Eval("ArrivalDt") %>' runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtArrivalDt"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtArrivalDt_TravelLine">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount_TravelLine" AutoPostBack="true" OnTextChanged="txtAmount_TravelLine_OnTextChanged"
Text='<%# Eval("Amount") %>' MaxLength="7" Width="200px" onblur="Fixed(this);"
CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender ID="ftbetxtAmount_TravelLine"
runat="server" TargetControlID="txtAmount_TravelLine" FilterMode="ValidChars"
FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_TravelLine"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="LnkAddTravelLineToGrv" runat="server" Font-Bold="True" ForeColor="#3366FF"
OnClick="LnkAddTravelLineToGrv_Click">Click To Add</asp:LinkButton><b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtgrandtotal" Style="text-align: right;" runat="server" ClientIDMode="Static"
CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="LnkAddTravelLineToGrv" />
</Triggers>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel_LodgingNLiving" runat="server" HeaderText="Lodging & living">
<ContentTemplate>
<div id="div_LodgingNLiving">
<asp:UpdatePanel ID="UpPanel_LodgingNLiving" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkAddLodgingLivingToGrv" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel_LodgingLiving" runat="server">
<asp:GridView ID="grvLodgingLiving" OnRowDataBound="grvLodgingLiving_RowDataBound"
CssClass="tabledata" runat="server" ShowFooter="True" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" Width="100%">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("City") %>' onkeypress="return Alpha(event);"
ID="txtCity_LodgingNLiving" Width="80px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lodging Nights">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Lodging_Nights") %>' ID="txtLodgingNights_LodgingNLiving"
onkeypress="return OnlyNum(event);" Width="50px" MaxLength="3" CssClass="txtbox"
runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lodging Days">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Lodging_Days") %>' ID="txtLodgingDays_LodgingNLiving"
onkeypress="return OnlyNum(event);" Width="50px" MaxLength="3" CssClass="txtbox"
runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hotel/Lodge Name">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Hotel_LodgeName") %>' MaxLength="50" onkeypress="return Alpha(event);"
ID="txtHotelLodgename_LodgingNLiving" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check-In Date">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("CheckInDt") %>' ID="txtCheckinDt_LodgingNLiving" runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="Cal_txtCheckinDt_LodgingNLiving"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtCheckinDt_LodgingNLiving" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check-Out Date">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("CheckOutDt") %>' ID="txtCheckoutDt_LodgingNLiving" runat="server"
ClientIDMode="Static" CssClass="FormText"></asp:TextBox><asp:CalendarExtender ID="CaltxtCheckoutDt_LodgingNLiving"
CssClass="MyCalendar" runat="server" Format="yyyy/MM/dd" TargetControlID="txtCheckoutDt_LodgingNLiving" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remark">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Remark") %>' CssClass="txtbox" ID="txtRemark_LodgingNLiving"
runat="server" Height="50px" Width="80px" MaxLength="100"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox Text='<%# Eval("Amount") %>' AutoPostBack="true" OnTextChanged="txtAmount_LodgingNLiving_OnTextChanged"
MaxLength="7" ID="txtAmount_LodgingNLiving" Width="70px" onblur="Fixed(this);"
CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender ID="Ftb_txtAmount_LodgingNLiving"
runat="server" TargetControlID="txtAmount_LodgingNLiving" FilterMode="ValidChars"
FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_LodgingLiving"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="lnkAddLodgingLivingToGrv" OnClick="LnkAddLodgingLivingToGrv_Click"
runat="server" Font-Bold="True" ForeColor="#3366FF">Click To Add</asp:LinkButton><b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtGrandTotal_LodgingLiving" Style="text-align: right;" runat="server"
ClientIDMode="Static" CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel_IncidentalCost" runat="server" HeaderText="Incidental Cost">
<ContentTemplate>
<div id="div_IncidentalCost">
<asp:UpdatePanel ID="UpPanel_IncidentalCost" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LnkAddIncidentalCostToGrid" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel_IncidentalCost" runat="server">
<asp:GridView ID="grvIncidentalCost" OnRowDataBound="grvIncidentalCost_RowDataBound"
CssClass="tabledata" runat="server" ShowFooter="True" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" Width="100%">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Place">
<ItemTemplate>
<asp:TextBox MaxLength="50" Text='<%# Eval("Place") %>' onkeypress="return Alpha(event);"
ID="txtPlace_IncidentalCost" Width="200px" CssClass="txtbox" runat="server"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount_IncidentalCost" MaxLength="7" Text='<%# Eval("Amount") %>'
Width="200px" onblur="Fixed(this);" CssClass="txtbox" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender
ID="Ftb_txtAmount_IncidentalCost" runat="server" TargetControlID="txtAmount_IncidentalCost"
FilterMode="ValidChars" FilterType="Custom" ValidChars="0123456789.">
</asp:FilteredTextBoxExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remark">
<ItemTemplate>
<asp:TextBox CssClass="txtbox" AutoPostBack="true" OnTextChanged="txtRemark_IncidentalCost_OnTextChanged"
Text='<%# Eval("Remark") %>' ID="txtRemark_IncidentalCost" runat="server" Height="50px"
TextMode="MultiLine" Width="463px" MaxLength="100"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D">
<ItemTemplate>
<asp:LinkButton ID="lnkDel" runat="server" OnCommand="DeleteRowHandler_IncidentalCost"
Text="D"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<table width="100%">
<tr>
<td align="left">
<asp:LinkButton ID="LnkAddIncidentalCostToGrid" runat="server"
Font-Bold="True" ForeColor="#3366FF"
OnClick="LnkAddIncidentalCostToGrid_Click">
Click To Add</asp:LinkButton>
<b>
(Note: D = Delete) </b>
</td>
<td align="right">
<b>Grand Total: </b>
<asp:TextBox ID="txtGrandTotal_IncidentalCost"
Style="text-align: right;" runat="server"
ClientIDMode="Static" CssClass="FormText" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
Problem is your ClientIDMode property on Textboxes
ClientIDMode="Static"
You need to remove abvoe attribute from your GridView code, because if you use it, all your TextBox controls will have the same ID, "txtCheckoutDt_LodgingNLiving" for this particular control on it calender extender is set. The CalendarExtender controls will find the first value (which is on the first row) and will be all mapped to it.
If you want to refine the patterns of your control ID assignment, here's more about the topic.
I tried with this but it's not working:
function validationsBirdstra() {
var grid = document.getElementById('<%=GVBirdstransfer.ClientID%>');
var theTextBoxvalue = grid.rows[0].cells[1].children[0].value;
if (theTextBoxvalue == "") {
alert('enter Type please');
return false;
}
}
and my gridview is
<table style="clear: both; float: none; margin-right: auto; margin-left: auto; font: 13px Verdana;">
<tbody>
<tr>
<td>
<asp:GridView ID="GVBirdstransfer" runat="server" BorderColor="#BDBDBD" ShowFooter="True"
CssClass="center" OnRowDataBound="GVBirdstransfer_RowDataBound" GridLines="Horizontal"
OnRowDeleting="GVBirdstransfer_RowDeleting" AutoGenerateColumns="False">
<EmptyDataTemplate>
No Records found</EmptyDataTemplate>
<Columns>
<asp:TemplateField ItemStyle-Width="20px" HeaderText="SNo">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltype" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVbirdtype" runat="server" ControlToValidate="ddltype"
ValidationGroup="GridView1" InitialValue="Select Me" Display="Dynamic" ErrorMessage="Please select Type"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEbirdtype" runat="Server" TargetControlID="RFVbirdtype"
EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Branch">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltobranch" runat="server" AutoPostBack="true">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
</asp:DropDownList>
<%--<asp:RequiredFieldValidator ID="RFVfrmbranch" runat="server" ControlToValidate="ddltobranch"
ValidationGroup="GridView1" InitialValue="0" Display="None" ErrorMessage="Please select Branch "></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEfrmbranch" runat="Server" TargetControlID="RFVfrmbranch"
EnableViewState="false" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birds">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtbirds" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtbirds"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mortality">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtmortality" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="txtmortality"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtweight" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txtweight"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GRNo">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtgrno" Width="70px" MaxLength="15" runat="server" AutoPostBack="true"
onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="txtgrno"
ValidationGroup="GridView1" Display="Static" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="BtnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" ValidationGroup="GridView1"
CausesValidation="true" />
</FooterTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
<%-- <tr>
<td align="center" style="padding-right: 10px">
<b>Total Weight:</b>
<asp:TextBox ID="txtTotal1" runat="server" Width="80px" />
</td>
</tr>--%>
<tr>
<td align="center">
<asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnSave_Click" OnClientClick="return validationsBirdstra();"
ValidationGroup="GridView1" CausesValidation="true" Style="height: 26px" />
</td>
</tr>
</tbody>
</table>
I had created gridview. In that I have some dropdownlists and some textboxes. Now I want to put validations for those.
If you are using RequiredFieldValidator then why are you going for Javascript. Just Remove OnClientClick in Button and try, It will fire.
And Set Display as Dynamic in RequiredFieldValidator
Try this
<table style="clear: both; float: none; margin-right: auto; margin-left: auto; font: 13px Verdana;">
<tbody>
<tr>
<td>
<asp:GridView ID="GVBirdstransfer" runat="server" BorderColor="#BDBDBD" ShowFooter="True"
CssClass="center" OnRowDataBound="GVBirdstransfer_RowDataBound" GridLines="Horizontal"
OnRowDeleting="GVBirdstransfer_RowDeleting" AutoGenerateColumns="False">
<EmptyDataTemplate>
No Records found</EmptyDataTemplate>
<Columns>
<asp:TemplateField ItemStyle-Width="20px" HeaderText="SNo">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
<ItemStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltype" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVbirdtype" runat="server" ControlToValidate="ddltype"
ValidationGroup="GridView1" InitialValue="Select Me" Display="Dynamic" ErrorMessage="Please select Type"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEbirdtype" runat="Server" TargetControlID="RFVbirdtype"
EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Branch">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:DropDownList ID="ddltobranch" runat="server" AutoPostBack="true">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
</asp:DropDownList>
<%--<asp:RequiredFieldValidator ID="RFVfrmbranch" runat="server" ControlToValidate="ddltobranch"
ValidationGroup="GridView1" InitialValue="0" Display="None" ErrorMessage="Please select Branch "></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="VCEfrmbranch" runat="Server" TargetControlID="RFVfrmbranch"
EnableViewState="false" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birds">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtbirds" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtbirds"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mortality">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtmortality" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="txtmortality"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtweight" Width="70px" MaxLength="15" runat="server" onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txtweight"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GRNo">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:TextBox ID="txtgrno" Width="70px" MaxLength="15" runat="server" AutoPostBack="true"
onkeypress="return validatenumerics(event)"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="txtgrno"
ValidationGroup="GridView1" Display="Dynamic" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="BtnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" ValidationGroup="GridView1"
CausesValidation="true" />
</FooterTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
<%-- <tr>
<td align="center" style="padding-right: 10px">
<b>Total Weight:</b>
<asp:TextBox ID="txtTotal1" runat="server" Width="80px" />
</td>
</tr>--%>
<tr>
<td align="center">
<asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnSave_Click" ValidationGroup="GridView1" CausesValidation="true" Style="height: 26px" />
</td>
</tr>
</tbody>
</table>
After browsing your web open the page source and look for the grid view.
you will get the client id there.now replace the <%=GVBirdstransfer.ClientID%> with your client id and check
I have a UserControl which is a nested GridView (facebook like wall), i want to load posts on scrolling down. I am following this article..
CLICK ME
The problem is that this method is using the first column's last row to get the last productid
something like this
var lastProductId = $("#GridViewUserScraps tr:last").children("td:first").html();
But in my case i am not displaying any id in any of the columns of the UserControl's GridView though i have a ScrapId column(primary key) in database. How can i load Posts on scrolling down? how can i make it work?
My UserControl:
<div id="divProducts" style="height:700px;overflow:auto">
<asp:GridView ID="GridViewUserScraps" ItemStyle-VerticalAlign="Top" AutoGenerateColumns="False"
GridLines="None" Width="100%" ShowHeader="False" runat="server" AlternatingRowStyle-BackColor="#A5A5A5"
CellPadding="4" ForeColor="#333333" DataKeyNames="ScrapId" OnRowCommand="GridViewRowCommand">
<Columns>
<asp:TemplateField>
<FooterTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">Load More</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<table align="left" cellpadding="1" cellspacing="2">
<tr>
<td>
<a href='<%#getUserHREF(Container.DataItem)%>'>
<img align="middle" src='<%#getSRC(Container.DataItem)%>' border="0" width="50px" /></a>
</td>
<td>
</td>
</tr>
</table>
<div align="justify">
<b>
<%#DataBinder.Eval(Container.DataItem,"firstname")%>
<div>
<asp:HiddenField ID="hiddenLastProductID" runat="server" Value='<%# Eval("id") %>' />
</div>
</b>
<br />
<%#DataBinder.Eval(Container.DataItem, "Message")%>
<br />
<asp:Image ID="Image" runat="server" ImageUrl='<%# Eval("url") %>' style="max-width:500px;" />
</div>
<span class="SmallBlackText">Posted On: </span>
<asp:Label ID="lblSendDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SendDate")%>'></asp:Label>
</span>
<br />
<%-- <asp:LinkButton ID="lnklike" runat="server"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
CommandName="LikeCmd">Like</asp:LinkButton>
<asp:LinkButton ID="lnkunlike" runat="server">unlike</asp:LinkButton>--%>
<asp:ImageButton ID="lnklike" runat="server" ImageUrl="~/Images/thumbsup.png" Height="20px"
Width="20px" CommandName="like" CommandArgument='<%# Eval("ScrapId")%>' />
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnklike" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Controls_GetUserScraps.abc((int)Eval("ScrapId")) %>' />
</ContentTemplate>
</asp:UpdatePanel>
<%--<asp:Label ID="Label1" runat="server" Text='<%# WebPageName.StaticMethodName((int)Eval("ScrapId")) %>' />--%>
<asp:ImageButton ID="lnkunlike" runat="server" CommandArgument='<%# Eval("ScrapId")%>'
CommandName="unlike" Height="20px" ImageUrl="~/Images/thumbsdown.png" Width="20px" />
<asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkunlike" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Controls_GetUserScraps.xyz((int)Eval("ScrapId")) %>'></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:LinkButton ID="lnkcomment" runat="server">Comment</asp:LinkButton>
<asp:LinkButton ID="lnkviewall" runat="server" CommandName="viewall" CommandArgument='<%# Eval("ScrapId")%>'>View All</asp:LinkButton>
<br />
<asp:Panel ID="Pnlchildgrid" runat="server">
<asp:GridView ID="childgrid" runat="server" AutoGenerateColumns="False" OnRowCommand="childgrid_RowCommand"
Style="width: 450px; float: right;">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table align="left" cellpadding="1" cellspacing="2">
<tr>
<td>
<a href='<%#getUserHREF(Container.DataItem)%>'>
<img align="middle" src='<%#getSRC(Container.DataItem)%>' border="0" width="30px" /></a>
</td>
<td>
</td>
</tr>
</table>
<div align="justify">
<b>
<%#DataBinder.Eval(Container.DataItem, "firstname")%></b><br />
<%#DataBinder.Eval(Container.DataItem, "commentmsg")%>
<br />
</div>
<span class="SmallBlackText">Posted On: </span>
<asp:Label ID="lblSendDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SendDate")%>'></asp:Label>
</span>
<br />
<asp:ImageButton ID="lnklike" runat="server" Height="20" Width="20" CommandName="childlike"
CommandArgument='<%# Eval("commentid")%>' ImageUrl="~/Images/thumbsup.png" />
<asp:Label ID="Label1" runat="server" Text='<%# Controls_GetUserScraps.abc1((int)Eval("commentid")) %>' />
<asp:ImageButton ID="lnkunlike" runat="server" CommandArgument='<%# Eval("commentid")%>'
CommandName="childunlike" Height="20" ImageUrl="~/Images/thumbsdown.png" Width="20" />
<asp:Label ID="Label2" runat="server" Text='<%# Controls_GetUserScraps.xyz1((int)Eval("commentid")) %>'></asp:Label>
<%-- <asp:LinkButton ID="lnkcomment" runat="server">Comment11111</asp:LinkButton>--%>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Panel ID="Panel1" runat="server">
<asp:TextBox ID="txtcomment" runat="server" Width="500px" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Comment" CommandName="comment" CommandArgument='<%# Eval("ScrapId")%>' />
</asp:Panel>
</asp:Panel>
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
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" />