I've been trying to implement the jquery validator that is the suggested answer here: jQuery Validation plugin in ASP.NET Web Forms
but in this and every other example I've found it requires that the elements to be validated are in a form. This may be a newbie question, but I have an asp:textbox (rather than an input) inside an asp:gridview and I can't get the validation to work. Is there a way to nest some of this in a form or do one of these asp functions generate a form automatically in html?
If it helps, here is the jquery code I'm using and my gridview:
<script type = "text/javascript">
$(function() {
// You can specify some validation options here but not rules and messages
$('form').validate();
// Add a custom class to your name mangled input and add rules like this
$('textbox[id$=NPI]').rules('add', {
required: true,
messages: {
required: 'Some custom message for the username required field'
}
});
});
</script>
<div style="overflow:auto; height:300px;">
<asp:GridView ID="SetRules" runat="server" AutoGenerateColumns="False" DataSourceID="AttributesRules" OnDataBound="Anchor_Changed"
class="styleGrid archGrid validation" AlternatingRowStyle-CssClass = "styleGridAlt" DataKeyNames="banner, pricinggroupkey, attribute, tieranchor, tierother">
<Columns>
<asp:TemplateField HeaderText="New Price Index" SortExpression="NewPriceIndex">
<ItemTemplate>
<asp:TextBox ID="NPI" class="NumVal" runat="server"
Text='<%# Bind("NewPriceIndex", "{0:N2}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="New Index Range" SortExpression="NewIndexRange">
<ItemTemplate>
<asp:TextBox ID="NIR" class="NumVal" runat="server"
Text='<%# Bind("NewIndexRange", "{0:N2}") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>