trouble in getting dynamic id`s for datepicker - asp.net

i want to generate a dynamic id of my datepicker. below jquery function shows the datetimepicker as the id is defined as static.
$(function () {
var dates = $("#ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0").datepicker(
{
dateFormat: 'dd/mm/yy',
defaultDate: '+1w',
changeMonth: false,
numberOfMonths: 1,
showOn: 'both',
buttonImage: 'Images/calendar_month.png',
buttonImageOnly: true,
onSelect: function (selectedDate) {
var option = this.id == "ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0" ? "minDate" : "maxDate",
instance = $(this).data("datepicker");
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
I want to generate a dynamic ID for the DatePicker. and How that ive tried various time but couldnt find the actual way of doing.Thanks.
<asp:GridView ID="gvdLCStatus" runat="server" DataKeyNames="LCID" AutoGenerateColumns="false"
AllowPaging="True" PageSize="4" EmptyDataText="No Record Found" CssClass="mGrid"
OnPageIndexChanging="gvdLCStatus_PageIndexChanging" OnRowCommand="gvdLCStatus_RowCommand"
OnSelectedIndexChanged="gvdLCStatus_SelectedIndexChanged" OnRowDataBound="gvdLCStatus_RowDataBound"
OnRowCreated="gvdLCStatus_RowCreated">
<AlternatingRowStyle CssClass="test" />
<Columns>
<asp:TemplateField HeaderText="LC Number">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("LCID") %>' Visible="false"></asp:Label>
<a href="#" onclick="linkbtnTest('<%# "#"+Eval("LCNumber") %>')">
<%# Eval("LCNumber") %></a>
<%-- <div id='<%# Eval("ShipmentID") %>' style="display: none;">
</div>--%>
<div id='<%# Eval("LCNumber") %>' style="display: none;">
<asp:GridView ID="gvShipmentStatus" runat="server" AutoGenerateColumns="false" DataKeyNames="ShipmentID"
OnRowCommand="gvShipmentStatus_RowCommand" OnRowDataBound="gvShipmentStatus_RowDataBound"
CssClass="mGrid">
<Columns>
<asp:BoundField DataField="InvoiceNumber" HeaderText="Invoice Number" />
<asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date" />
<asp:BoundField DataField="BLNumber" HeaderText="B/L Number" />
<asp:BoundField DataField="BLDate" HeaderText="B/L Date" />
<asp:BoundField DataField="VesselName" HeaderText="Vessel Name" />
<asp:BoundField DataField="VoyageNumber" HeaderText="Voyage Number" />
<asp:BoundField DataField="DueDate" HeaderText="Due Date" />
<asp:BoundField DataField="ContractedShipmentSchedule" HeaderText="Shipment Schedule" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="ImgShipmentDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteShipmentRecord"
CommandArgument='<%# Eval("ShipmentID") %>' AlternateText="DeleteShipmentRecord"
OnClientClick="return confirm_delete();" Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<%-- <asp:ImageButton ID="ImgShipmentEdit" runat="server" ImageUrl="~/Images/edit.png"
CommandName="EditShipmentRecord" ImageAlign="Middle" CommandArgument='<%# Eval("ShipmentID") %>'
AlternateText="EditShipmentRecord" OnClientClick='linkbtnTest(<%# Eval("ShipmentID) %>)' />
--%>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="EditShipmentRecord"
CommandArgument='<%# Eval("ShipmentID")+":"+Eval("LCStatusID")%>'>
<%--<asp:Label ID="Label2" runat="server" Text='<%# Eval("ShipmentID") %>' Visible="true"></asp:Label>--%> <img src="Images/edit.png" alt="Edit" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<%--</div>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ContractNumber" HeaderText="Contract Number" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Qty" HeaderText="Quantity" />
<asp:TemplateField>
<ItemTemplate>
Add Shipment Status
<div id='<%# Eval("LCID") %>' style="display: none;">
<table>
<tr>
<td class="td_records" style="padding-top: 5px;">
Invoice Number
</td>
<td class="td_records" style="padding-top: 5px;">
Invoice Date (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Number
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Date (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtInvoiceNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtInvoiceDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLDate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="td_records" style="padding-top: 5px;">
VesselName
</td>
<td class="td_records" style="padding-top: 5px;">
VoyageNumber
</td>
<td class="td_records" style="padding-top: 5px;">
DueDate (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
ShipmntSchedule (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVesselName" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtVoyageNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtDueDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtShipmntSchedule" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-top: 10px;">
<asp:Button ID="btnSubmitShipment" runat="server" Text="Submit" CommandName="Select"
OnCommand="btnSubmitShipment_Command" CssClass="btnSubmitCSS" />
<asp:Button ID="btnResetShipmentRecord" runat="server" Text="Reset" CssClass="btnSubmitCSS" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="DeleteRecord" OnClientClick="return confirm_delete();"
Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/edit.png" CommandName="EditRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="EditRecord" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>

As an option you may use such selector:
var dates = $("[id*='txtInvoiceDate']", "#<%= gvdLCStatus.ClientID %>")​
But better consider to set CssClass property on textboxes and use class selector

Why do you select by id? Why don't you go with class name? $('.datebox').dateTimepicker(...

i found an alternate of validating it with asp.net required field validators. No other option was there and had to maintain the time constraint.
Thanks Guys.

Related

Read Textboxes inside EditItemTemplate of Gridview and validate using jQuery

I have asp.net gridview control on a webform, which i used to add, edit and delete records of invoice list with four fields of AgreementNO(txtRANO), Invoice No(txtInvNo),Dispute Date(txtDisputeDate), Amount(txtInvAmount).User can add, edit and delete records as required.
I'm trying to validate the text boxes inside grid view item template and edit item template using jQuery since either txtInvNo and txtDisputeDate will have a value per record.
I can identify the text boxes in side empty and footer template as it will be single row and the ID of textboxes doesn't change dynamically.
But the ID s of textboxes changes for example txtInvNo_0,txtInvNo_1 and so on depend on number of rows, and jQuery could not identify using $(this).closest("tr").find("[id$=txtRANumber]") method.
I looked for many examples, and suggested to use css class and identifu each textbox with its css class name. I have applied same css class for all textboxes.
is there any proper way to do this, other wise will end up in number of css class as unique class name required. code below.
<asp:GridView ID="grdCNoteRADetailAdd" runat="server" AutoGenerateColumns="false"
ShowFooter="true" CssClass="grdMain" GridLines="None" DataKeyNames="CNRecID"
OnRowEditing="EditRADetail" OnRowUpdating="UpdateRADetail" OnRowCancelingEdit="CancelEditRADetail"
Width="100%">
<HeaderStyle CssClass="grdheader" />
<RowStyle CssClass="grdItem" VerticalAlign="Top" />
<AlternatingRowStyle CssClass="grdaltItem" VerticalAlign="Top" />
<FooterStyle VerticalAlign="Top" />
<Columns>
<asp:TemplateField HeaderText="RA Number" HeaderStyle-Width="25%" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblRANumber" runat="server" Text='<%# Eval("RANumber")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRANumber" runat="server" Text='<%# Eval("RANumber")%>' CssClass="txtbox1" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="edRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<tr>
<td style="width: 25%;">
<asp:TextBox ID="txtRANumber" runat="server" CssClass="txtbox1" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="newNRA"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ErrorMessage="!" ValidationGroup="newNRA"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$"></asp:RegularExpressionValidator>
</td>
<td style="width: 25%;">
<asp:TextBox ID="txtInvNo" runat="server" CssClass="txtbox2" Width="90%" ValidationGroup="newNRA"></asp:TextBox>
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo" ValidationGroup="newNRA"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$"></asp:RegularExpressionValidator>
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%"></asp:TextBox>
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtCreditAmount" runat="server" CssClass="txtbox1" Width="85%" ValidationGroup="newNRA"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationGroup="newNRA"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator9" runat="server" ErrorMessage="!" ValidationGroup="newNRA"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationExpression="^\d+(\.\d{1,2})?$"></asp:RegularExpressionValidator>
</td>
<td style="width: 10%;">
<asp:Button ID="btnAddRF" runat="server" Text="Add" OnClick="AddNewRADetail" ValidationGroup="newNRA"/>
</td>
</tr>
<tr>
<td></td>
<td class="tdsubhead2" style="text-align: center;">Total
</td>
<td>
<asp:Label ID="lblCNoteTotal" runat="server" Text=""></asp:Label>
</td>
<td></td>
</tr>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="25%" HeaderText="Invoice No" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblInvNo" runat="server" Text='<%# Eval("InvoiceNo")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtInvNo" runat="server" Text='<%# Eval("InvoiceNo")%>' CssClass="txtbox2" Width="95%" ValidationGroup="edRa"></asp:TextBox>
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="20%" HeaderText="Dispute Date" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblDispute_Date" runat="server" Text='<%# Eval("Dispute_Date")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblDisputeDate" runat="server" Text='<%# Eval("Dispute_Date")%>' Visible='<%# IIf(Eval("IsInvoice") = True, True, False)%>'></asp:Label>
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%" Text='<%# Eval("Dispute_Date")%>' Visible='<%# If(Eval("IsInvoice") = True, False, True)%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="20%" HeaderText="Credit Amount" HeaderStyle-CssClass="grdItemborder"
ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblCreditAmount" runat="server" Text='<%# Eval("CNAmount")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCreditAmount" runat="server" Text='<%# Eval("CNAmount")%>' CssClass="txtbox1" Width="90%" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="!" ValidationGroup="edRa"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationExpression="^\d+(\.\d{1,2})?$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<%--<asp:CommandField ShowEditButton="True" />--%>
<asp:TemplateField ShowHeader="False" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit" ValidationGroup="vgEdit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<table style="width: 100%">
<tr>
<td>
<asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" ValidationGroup="edRa"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkRemoveRF" runat="server" CommandArgument='<%# Eval("CNRecID")%>'
Text="Delete" OnClick="DeleteRADetail" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<%--<asp:TemplateField HeaderStyle-Width="10%" HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:LinkButton ID="lnkRemoveRF" runat="server" CommandArgument='<%# Eval("CNRecID")%>'
Text="Delete" OnClick="DeleteRADetail" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
<EmptyDataTemplate>
<tr>
<td class="tdsubhead2" style="width: 25%; text-align: center;">RA Number
</td>
<td class="tdsubhead2" style="width: 25%; text-align: center;">Invoice No
</td>
<td class="tdsubhead2" style="width: 20%; text-align: center;">Dispute Date
</td>
<td class="tdsubhead2" style="width: 20%; text-align: center;">Credit Amount
</td>
<td style="border: 0px solid grey; width: 10%;"></td>
</tr>
<tr>
<td style="text-align: center">
<asp:TextBox ID="txtRANumber" runat="server" CssClass="txtbox1" ValidationGroup="newRa" Width="90%" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="newRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator10" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber"
ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="vertical-align: top; text-align: center">
<asp:TextBox ID="txtInvNo" runat="server" CssClass="txtbox2" ValidationGroup="newRa" Width="90%" />
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="vertical-align: top; text-align: center">
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%"></asp:TextBox>
</td>
<td style="text-align: center">
<asp:TextBox ID="txtCreditAmount" runat="server" CssClass="txtbox1" Width="75%" ValidationGroup="newRa" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="!"
ValidationGroup="newRa" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator12" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"
ValidationExpression="^\d+(\.\d{1,2})?$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="width: 10%">
<asp:Button ID="btnAddRF" runat="server" Text="Add" OnClick="AddNewRADetail" CommandName="emptyInsert"
CausesValidation="true" CssClass="buttonScreenSpec" ValidationGroup="newRa" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="tdsubhead2" style="text-align: center;">Total
</td>
<td>
<asp:Label ID="lblCNoteTotal" runat="server" Text=""></asp:Label>
</td>
<td></td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
JQuery Code Below/
/Add New Record
$("[id$=grdCNoteRADetailAdd] [id$=btnAddRF]").click(function () {
var raRow = $(this).closest("tr");
alert($(this).closest("tr input[type='text']").length);
var txtRaNo = raRow.find("[id$=txtRANumber]");
var txtInvNo = raRow.find("[id$=txtInvNo]");
var txtDisDate = raRow.find("[id$=txtDisputeDate]");
if ($.trim(txtRaNo.val()) != "")
{
if ($.trim(txtInvNo.val()) == "" && $.trim(txtDisDate.val()) == "")
{
var msg = "Both Invoive No and Dispute Date cannot be empty.\nIf system generated invoice is not available, specify the date when was the dispute happend.\n ";
msg += "For example : Date when the tarffic fine was charged directly to customer by police..!"
alert(msg);
return false;
}
}
return true;
});
//Edit Record using Update Link button
//This does not work as txtRANumber,txtInvNo and txtDisputeDate are dynamically gaving index at the end as txtDisputeDate_0,1 etc based on number of rows in the grid
$('#<%=grdCNoteRADetailAdd.ClientID %> a:contains(Update)').click(function () {
var raRow = $(this).closest("tr");
var txtRaNo = raRow.find("[id$=txtRANumber]");
var txtInvNo = raRow.find("[id$=txtInvNo]");
var txtDisDate = raRow.find("[id$=txtDisputeDate]");
alert(txtRaNo.attr("id"));
if ($.trim(txtRaNo.val()) != "") {
if ($.trim(txtInvNo.val()) == "" && $.trim(txtDisDate.val()) == "") {
//alert('fuck2');
var msg = "Both Invoive No and Dispute Date cannot be empty.\nIf system generated invoice is not available, specify the date when was the dispute happend.\n ";
msg += "For example : Date when the tarffic fine was charged directly to customer by police..!"
alert(msg);
return false;
}
}
return true;
});
I have found the answer for the issue and post here, to help others.
Note: 1. Text box placed inside will be created a dynamic ID as "textboxName(number)". So JQuery will not identify the text box using its id.
I added a css class name (same as textbox ID) along with actual css class name.
for example, my textbox ID ="txtRANumber" and CssClass="txtRANumber txtbox1".
here txtbox1 is the css class , and txtRANumber class i added to identify the textbox using its class name using JQuery.Gridview code extract and JQuery code extract are below.
$("[id*=grdCNoteRADetailAdd] [id*=lnkUpdate]").click(function () {
var raNo = $('.txtRANumber').val(); // txtRANumber text box identifiied using its css class name
var invNo = $('.txtInvNo').val();
var disDate = $('.txtbox2JQDP').val();
if ($.trim(raNo) == "") {
var msg="Enter RA number"
alert(msg);
return false;
}
}
return true;
});
<EditItemTemplate>
<asp:TextBox ID="txtRANumber" runat="server" Text='<%# Eval("RANumber")%>' CssClass="txtRANumber txtbox1" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="edRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>

Required Field Validators disappear in an update panel

I have an Update Panel which contains a GridView. 3 TextBoxes and a DropDownList control are Validated. I also have 3 different DDLs and 3 Checkbox controls in the panel that each trigger a rebind of the Gridview. When one of the un-validated DDLs or Checkboxes is changed they all fire the same changed event and I lose all of the Validation on the TextBoxes and the 1 DDL.
I'm a bit confused as to whether I should be setting Initial values on the validated or un-validated controls, if I should "group" the validation, and which set of controls needs to have the CausesValidation flag set. I hate to spam with massive amounts of code, but considering how much there is in this update panel....
<asp:UpdatePanel ID="UpdatePanel_Search" runat="server" >
<ContentTemplate>
<table class="auto-style2">
<tr>
<td>
<table class="auto-style1">
<tr>
<td class="auto-style3">
<div>
<table class="auto-style1" border="1px" frame="void">
<tr>
<td bgcolor="#00198D" style="text-align: center" class="auto-style19">
<asp:Label ID="FilterLabel3" runat="server" ForeColor="White" Text="Used by OEM"></asp:Label>
</td>
<td bgcolor="#00198D" style="text-align: center" class="auto-style9">
<asp:Label ID="FilterLabel4" runat="server" ForeColor="White" Text="Item Type"></asp:Label>
</td>
<td bgcolor="#00198D" style="text-align: center" class="auto-style24">
<asp:Label ID="FilterLabel5" runat="server" ForeColor="White" Text="Group Type"></asp:Label>
</td>
<td bgcolor="#00198D" style="text-align: center" class="auto-style12">
<asp:Label ID="FilterLabel6" runat="server" ForeColor="White" Text="Part Active"></asp:Label>
</td>
<td bgcolor="#00198D" style="text-align: center" class="auto-style17">
<asp:Label ID="FilterLabel7" runat="server" ForeColor="White" Text="Non-Inventory Part"></asp:Label>
</td>
<td bgcolor="#00198D" style="text-align: center" class="auto-style7">
<asp:Label ID="FilterLabel8" runat="server" ForeColor="White" Text="Part In Stock"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style19">
<asp:DropDownList ID="DDL_OEM" runat="server" Height="27px" Width="150px" AutoPostBack="True" AppendDataBoundItems="True" OnSelectedIndexChanged="Filter_DataSet" ></asp:DropDownList>
</td>
<td class="auto-style9">
<asp:DropDownList ID="DDL_ItemTypes" runat="server" Height="27px" Width="150px" AutoPostBack="True" AppendDataBoundItems="True" OnSelectedIndexChanged="Filter_DataSet" ></asp:DropDownList>
</td>
<td class="auto-style9">
<asp:DropDownList ID="DDL_GroupTypes" runat="server" Height="27px" Width="150px" AutoPostBack="True" AppendDataBoundItems="True" OnSelectedIndexChanged="Filter_DataSet" ></asp:DropDownList>
</td>
<td class="auto-style12">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="Filter_DataSet" Checked="True" Style="text-align: center" />
</td>
<td class="auto-style17">
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="Filter_DataSet" Style="text-align: center" />
</td>
<td class="auto-style7">
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" OnCheckedChanged="Filter_DataSet" Style="text-align: center" />
</td>
</tr>
</table>
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox_Ticket_Search"
ErrorMessage="Ticket Number is Required. Enter NOTICKET if the item you are requesting is for your tech stock(i.e. a tool, USB drive, etc.)"
ForeColor="Red">
</asp:RequiredFieldValidator>
</div>
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox_Part_Search"
ErrorMessage="Part Number is Required. Select a Part from the Catalog before submitting a request."
ForeColor="Red">
</asp:RequiredFieldValidator>
</div>
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox_Serial_Search"
ErrorMessage="System Serial Number is Required. Enter NOSERIAL if the item you are requesting is for your tech stock(i.e. a tool, USB drive, etc.)"
ForeColor="Red">
</asp:RequiredFieldValidator>
</div>
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ControlToValidate="DDL_OEM_submit0"
ErrorMessage="System Model is a required field. Please select a Model from the Drop Down below."
InitialValue="0"
ForeColor="Red">
</asp:RequiredFieldValidator>
</div>
</td>
</tr>
<table class="auto-style1">
<tr>
<td class="auto-style34">
<table class="auto-style1">
<tr>
<td>
<asp:Label ID="Label_Comments_Search" runat="server" Text="Comments:"></asp:Label>
</td>
</tr>
<tr>
<td style="text-align: left">
<asp:TextBox runat="server"
ID="TextBox_Comments_Search"
TextMode="multiline"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible" Height="100px" Width="300px">
</asp:TextBox>
</td>
</tr>
</table>
</td>
<td class="auto-style29">
<table class="auto-style1">
<tr>
<td class="auto-style4">
<asp:Label ID="Label_Ticket_Search" runat="server" Text="Ticket #:"></asp:Label>
</td>
<td class="auto-style32">
<asp:TextBox ID="TextBox_Ticket_Search" runat="server"></asp:TextBox>
<span class="auto-style23">*</span></td>
</td>
</tr>
<tr>
<td style="text-align: right">
<asp:Label ID="Label_Part_Search" runat="server" Text="Part #:"></asp:Label>
</td>
<td class="auto-style32">
<asp:TextBox ID="TextBox_Part_Search" runat="server" ReadOnly="true" BackColor="#CCCCCC"></asp:TextBox>
<span class="auto-style23">*</span>
</td>
</tr>
<tr>
<td style="text-align: right" class="auto-style21">
<asp:Label ID="Label12" runat="server" Text="Serial #:"></asp:Label></td>
<td class="auto-style32">
<asp:TextBox ID="TextBox_Serial_Search" runat="server"></asp:TextBox>
<span class="auto-style23">*</span></td>
</tr>
<tr>
<td style="text-align: right" class="auto-style21">
<asp:Label ID="Label_Damage_Search" runat="server" Text="Part Damaged:"></asp:Label>
</td>
<td style="text-align: left" class="auto-style31">
<asp:CheckBox ID="CheckBox_Damage_Search" runat="server"></asp:CheckBox>
</td>
</tr>
</table>
</td>
<td>
<table class="auto-style25">
<tr>
<td>
<table class="auto-style25">
<tr>
<td>
<asp:Label ID="Label15" runat="server" Style="text-align: left" Text="Model:"></asp:Label>
</td>
<td align="left">
<asp:DropDownList ID="DDL_OEM_submit0" runat="server">
</asp:DropDownList>
<span class="auto-style23">*</span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" Text="Submit Part Request" OnClick="Button2_Click" />
</td>
</tr>
</table>
</td>
<table class="auto-style1">
<tr>
<td>
<table class="auto-style1">
<tr>
<td class="auto-style8" valign="top">
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="ID"
DataSourceID="SqlDataSource1"
EnableModelValidation="True"
AllowSorting="True"
OnSelectedIndexChanged="Gridview1_SelectedIndexChanged"
AutoGenerateSelectButton="True"
BackColor="White"
BorderColor="#999999"
BorderStyle="None"
BorderWidth="1px"
CellPadding="3"
GridLines="Vertical" HorizontalAlign="Justify">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#00198D" ForeColor="White" />
<PagerStyle ForeColor="Black" BackColor="#999999" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="#DCDCDC" />
<EmptyDataTemplate>
No records could be retrieved from the database. We apologize for the inconvenience.
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="OEMPartCode" HeaderText="OEMPartCode" SortExpression="OEMPartCode" />
<asp:BoundField DataField="OEM" HeaderText="OEM" InsertVisible="False" ReadOnly="True" SortExpression="OEM" />
<asp:BoundField DataField="Sub Categories" HeaderText="Models" InsertVisible="False" ReadOnly="True" SortExpression="Sub Categories" />
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="Red" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</td>
<td style="text-align: left" valign="top">
<asp:DetailsView
ID="DetailsView1"
runat="server"
DataSourceID="SqlDataSource2"
Height="50px"
Width="556px"
CellPadding="4"
AutoGenerateRows="False"
OnDataBound="DetailsView1_OnDataBound"
ForeColor="White"
EnableModelValidation="True"
DataKeyNames="ID"
HorizontalAlign="Left"
Style="margin-right: 0px">
<FieldHeaderStyle BackColor="#00198D" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="OEMPartCode" HeaderText="OEMPartCode" />
<asp:BoundField DataField="PartCode2" HeaderText="PartCode2" />
<asp:TemplateField HeaderText="UsedByOEM">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("UsedByOEM") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ItemType">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("JoinedItemType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GroupType">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("JoinedGroupType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PartDesc" HeaderText="PartDescription" SortExpression="PartDesc" />
<asp:BoundField DataField="PartComment" HeaderText="PartComment" SortExpression="PartComment" />
<asp:BoundField DataField="PartCount" HeaderText="PartCount" SortExpression="PartCount" />
<asp:BoundField DataField="PartMin" HeaderText="PartMin" SortExpression="PartMin" />
<asp:CheckBoxField DataField="PartActive" HeaderText="PartActive" SortExpression="PartActive" />
<asp:BoundField DataField="MFRPartNumber" HeaderText="MFRPartNumber" SortExpression="MFRPartNumber" />
<asp:BoundField DataField="PartCapacity" HeaderText="PartCapacity" SortExpression="PartCapacity" />
<asp:CheckBoxField DataField="PreTurnRequired" HeaderText="PreTurnRequired" SortExpression="PreTurnRequired" />
<asp:TemplateField HeaderText="AssemblyPart">
<ItemTemplate>
<asp:Label ID="Label_AssemblyPart" runat="server" Text='<%# Bind("AssemblyPart") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Part Image">
<ItemTemplate>
<a href="javascript:void(window.open('<%# "ShowImage.aspx?PID="+ Eval("PartImage")%>','_blank','toolbar=no,menubar=no'))">
<asp:Image ID="FullImage" ToolTip="Click to download the full size image."
runat="server" ImageUrl='<%# "ShowThumb.aspx?size=120&PID="+ Eval("PartImage") %>' /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Part Image 2">
<ItemTemplate>
<a href="javascript:void(window.open('<%# "ShowImage.aspx?PID="+ Eval("PartImage2")%>','_blank','toolbar=no,menubar=no'))">
<asp:Image ID="Image1" ToolTip="Click to download the full size image."
runat="server" ImageUrl='<%# "ShowThumb.aspx?size=120&PID="+ Eval("PartImage2") %>' /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="NonInventoryPart" HeaderText="NonInventoryPart" SortExpression="NonInventoryPart" />
<asp:TemplateField HeaderText="Updated By">
<ItemTemplate>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Bind("CreatedByUser") %>' ReadOnly="True"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Modified">
<ItemTemplate>
<asp:Label ID="ModifiedDateLabel" runat="server" Text='<%# Bind("LastModifiedDate") %>' ReadOnly="True"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#00198D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#00198D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" ForeColor="Black" Width="300px" />
</asp:DetailsView>
</td>
</tr>
</table>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
DataSourceMode="DataSet"
SelectCommand="SELECT Stuff">
<FilterParameters>
<asp:ControlParameter Name="UsedByOEM" ControlID="DDL_OEM" PropertyName="SelectedValue" />
<asp:ControlParameter Name="ItemType" ControlID="DDL_ItemTypes" PropertyName="SelectedValue" />
<asp:ControlParameter Name="GroupType" ControlID="DDL_GroupTypes" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<a></a>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues"
SelectCommand="SELECT Stuff">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
Did you try giving the controls a group name?

collapsiblepanel collapse in code not collapsing

I have a panel that i have extended with collapsible extender. It is working perfectly until i try to collapse it by code.
The collapsible panel is shown inside a modal popup where user searches for some data, that is
shown in a grid , In every row of grid there is a select button that fires the row command event of the grid on which i am trying to close the panel.
Markup:
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnAdd"
PopupControlID="pnlpopup" CancelControlID="Cancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="320px" Width="530px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; height: 100%" cellpadding="0"
cellspacing="0">
<tr>
<td>
Bridge ID :
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvID" runat="server" ControlToValidate="txtID" ValidationGroup="vldAddBridge"
ErrorMessage="Please enter ID" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td>
Bridge Name :
<asp:TextBox ID="txtBridgeName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvBridgeName" runat="server" ControlToValidate="txtBridgeName"
ValidationGroup="vldAddBridge" ErrorMessage="Please enter bridge name." ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<td colspan="2" style="text-align: right; margin-left: 40px;">
<asp:Button ID="btnSearchUser" runat="server" OnClick="btnSearchUser_Click" TabIndex="5"
Text="Search" ValidationGroup="vgSearchMember" />
</td>
</tr>
<tr>
<td colspan="5" style="background-color: White" class="style6">
<asp:Label ID="lblSearchResults" runat="server"></asp:Label>
<asp:GridView ID="gvSearchResults" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" BorderWidth="1px" CellPadding="4" CssClass="gridviewBorder"
DataKeyNames="EmpId" ForeColor="Black" GridLines="Horizontal" PageSize="5" RowStyle-CssClass="style5"
TabIndex="7" Width="100%" OnPageIndexChanging="gvSearchResults_PageIndexChanging"
OnRowCommand="gvSearchResults_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelect" runat="server" Text="Select" CommandName="Select"
CommandArgument='<%# Eval("EmpId") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmpId" HeaderText="Employee ID" />
<asp:BoundField DataField="Alias" HeaderText="Username" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
</Columns>
</asp:GridView>
<br />
</td>
</tr>
</table>
</asp:Panel>
<asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" CollapseControlID="btnOwner"
ExpandControlID="btnOwner" TargetControlID="PnlRegister" Collapsed="true">
</asp:CollapsiblePanelExtender>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<asp:Button ID="btnSaveBridge" runat="server" Text="Save" OnClick="btnSaveBridge_Click"
ValidationGroup="vldAddBridge" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
<span style="display: none">
<input type="button" id="Cancel" /></span>
</td>
</tr>
</table>
</asp:Panel>
Code:
protected void gvSearchResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
//some business logic
CollapsiblePanelExtender1.Collapsed = true;
ModalPopupExtender1.Show();
}
}
It is not working the panel is always open ?? Any suggestions.....
You are missing
tr in your design. Please check it
Markup:
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnAdd"
PopupControlID="pnlpopup" CancelControlID="Cancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="320px" Width="530px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; height: 100%" cellpadding="0"
cellspacing="0">
<tr>
<td>
Bridge ID :
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvID" runat="server" ControlToValidate="txtID" ValidationGroup="vldAddBridge"
ErrorMessage="Please enter ID" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td>
Bridge Name :
<asp:TextBox ID="txtBridgeName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvBridgeName" runat="server" ControlToValidate="txtBridgeName"
ValidationGroup="vldAddBridge" ErrorMessage="Please enter bridge name." ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
**<tr> //This is missing**
<td colspan="2" style="text-align: right; margin-left: 40px;">
<asp:Button ID="btnSearchUser" runat="server" OnClick="btnSearchUser_Click" TabIndex="5"
Text="Search" ValidationGroup="vgSearchMember" />
</td>
</tr>
<tr>
<td colspan="5" style="background-color: White" class="style6">
<asp:Label ID="lblSearchResults" runat="server"></asp:Label>
<asp:GridView ID="gvSearchResults" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" BorderWidth="1px" CellPadding="4" CssClass="gridviewBorder"
DataKeyNames="EmpId" ForeColor="Black" GridLines="Horizontal" PageSize="5" RowStyle-CssClass="style5"
TabIndex="7" Width="100%" OnPageIndexChanging="gvSearchResults_PageIndexChanging"
OnRowCommand="gvSearchResults_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelect" runat="server" Text="Select" CommandName="Select"
CommandArgument='<%# Eval("EmpId") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmpId" HeaderText="Employee ID" />
<asp:BoundField DataField="Alias" HeaderText="Username" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
</Columns>
</asp:GridView>
<br />
</td>
</tr>
</table>
</asp:Panel>
<asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" CollapseControlID="btnOwner"
ExpandControlID="btnOwner" TargetControlID="PnlRegister" Collapsed="true">
</asp:CollapsiblePanelExtender>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<asp:Button ID="btnSaveBridge" runat="server" Text="Save" OnClick="btnSaveBridge_Click"
ValidationGroup="vldAddBridge" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
<span style="display: none">
<input type="button" id="Cancel" /></span>
</td>
</tr>
</table>
</asp:Panel>
Hope it solve your problem

update gridview field without dataBind

i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page

ListView with InsertItemTemplate doesnt work

<asp:ListView ID="lvWallPosts" runat="server"
onitemcommand="lvWallPosts_ItemCommand" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblWallPosts"
style="width:460px">
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<tr id="Tr2" style="height:72px" runat="server">
<td valign="top" class="EmployeeInfo">
<p>
<div class="wallmark"><asp:Image ID="imgFile" runat="server" CssClass="friendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"ByUsername").ToString() %>' />
<asp:Label ID="lblFrom" runat="server" Text='<%#Eval("ByUsername") %>' Font-Size="0.9em" Font-Underline="false" /><br />
<asp:Label ID="lblMessage" runat="server" Text='<%#Eval("Message") %>' Font-Size="0.9em" Font-Underline="false"/></div>
<asp:LinkButton CssClass="shareText" runat="server" ID="lblComment" CommandArgument='<%# Eval("Id") %>' CommandName="Insert" Font-Size="0.9em" Font-Underline="false">Comment</asp:LinkButton>
<asp:LinkButton CssClass="shareText" runat="server" ID="lbShare" CommandArgument='<%# Eval("Id") %>' CommandName="Share" Font-Size="0.9em" Font-Underline="false">Share</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I cant see the txtMessage control when I click on linkbutton comment.
try setting the linkbutton's commandname to "InitInsert" instead of "Insert"

Resources