how to select input field under asp:repeater element in jquery - javascript

<asp:UpdatePanel ID="radpnl1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Repeater ID="rpt_Template" runat="server">
<HeaderTemplate>
<table id="tblusers" width="100%" cellpadding="2" cellspacing="2">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="20%" class="table_row2">
Name :
</td>
<td class="table_row2">
<input type="text" id="txt_template" name="txt_template" value='<%# DataBinder.Eval(Container.DataItem, "TemplateName") %>'
maxlength="200" />
<input type="hidden" id="hdnDeletedIds" name="hdnDeletedIds" value="" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
I am new to Jquery. I want to know if i can select all the input fields above with id="txt_template" to compare their name using a Jquery function. As this is is under <asp:repeater> control, I'm not sure how to achieve this.

Inside the repeater, You need to use class instead of id. I'm not really sure but I thing the id you give to a server control with runat=server is not essentially the rendered id.
So use a class as follows
<asp:UpdatePanel ID="radpnl1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Repeater ID="rpt_Template" runat="server">
<HeaderTemplate>
<table id="tblusers" width="100%" cellpadding="2" cellspacing="2">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="20%" class="table_row2">
Name :
</td>
<td class="table_row2">
<input type="text" class='aSuperInput' id="txt_template" name="txt_template" value='<%# DataBinder.Eval(Container.DataItem, "TemplateName") %>'
maxlength="200" />
<input type="hidden" id="hdnDeletedIds" name="hdnDeletedIds" value="" />
</td>
</tr>
</table>
</ContentTemplate>
JQuery
$('.aSuperInput').change(function(){
//----
});
or
$('.aSuperInput').select(function(){
//----.blur(), .focus(), .unblur(), ect.
});

Related

Asp.net 2.0 error repeater button

I am trying to use a repeater and use ajax instead of the "EnableEventValidation='true'" but I get the error below on page unload. When I click on the button in the repeater the repeater1_ItemCommand does not get referenced
Error:
System.Collections.ListDictionaryInternal System.ArgumentException:
Invalid postback or callback argument. Event validation is enabled
using in configuration or <%#
Page EnableEventValidation="true" %> in a page
Code:
<asp:ToolkitScriptManager ID="MainSM" EnablePageMethods="true" runat="server" ScriptMode="Release" LoadScriptsBeforeUI="true">
</asp:ToolkitScriptManager>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table id="myTable" width="700" border="1" class = "mMMGrid" frame="box">
<th align=left>Page Image</th><th align=left>Page #</th><th align=left >Page Sequnce</th><tbody>
<tr>
<td width="15%">
<div id = "dPage" runat="server" >
<asp:ImageButton ID="imbtnCourseLink" runat="server" ImageUrl='<%#imPath(DataBinder.Eval(Container, "DataItem.ChunkFilePath"))%>' OnClick="imlink2" Width="75px" Height="75px" />
</div>
</td>
<td width="15%">
<strong>Pages</strong> : <asp:label ID="lblPage" Text='<%# Eval("Page")%>' runat="server"></asp:label> <br/>
</td>
<td width="65%">
<asp:ImageButton ID="imbtUp" runat="server" ImageUrl="~/SiteImages/go-up.png" Width="40" height="40" CommandName="UP" CommandArgument='<%# Eval("Page")%>'/>
<asp:ImageButton ID="imbtDown" runat="server" ImageUrl="~/SiteImages/go-down.png" Width="40" Height="40" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<triggers>
<asp:asyncpostbacktrigger controlid="imbtUp" eventname="Click" />
<asp:asyncpostbacktrigger controlid="Repeater1" eventname="ItemCommand" />
</triggers>
</asp:UpdatePanel>
<br />
</td>
</tr>
</tbody>
</table>
</ItemTemplate>
</asp:Repeater>

Check if All check box in Panel1 are checked to show a Panel2

I have 2 panels, of checkbox: In Panel1, if all checkbox are checked I need to show Panel2.
I have a HTML and a script but it's not working, I think that I'm missing somthing.
here is my code :
<body>
<asp:Panel ID="Panel1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="Title" runat="server" Text="Enter the Title"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Question1" runat="server" Text="Question1"></asp:Label>
</td>
<td>
<asp:CheckBox ID="CheckBox1" name="cb" runat="server" Checked="false" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Question2" runat="server" Text="Question2"></asp:Label>
</td>
<td>
<asp:CheckBox ID="CheckBox2" name="cb" runat="server" Checked="false" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Question3" runat="server" Text="Question3"></asp:Label>
</td>
<td>
<asp:CheckBox ID="CheckBox3" name="cb" runat="server" Checked="false" />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server">
<table>
<tr>
<td>
<asp:Label ID="Question4" runat="server" Text="Question4"></asp:Label>
</td>
<td>
<asp:CheckBox ID="CheckBox4" runat="server" Checked="false" />
</td>
</tr>
</table>
</asp:Panel>
<table>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
</td>
</tr>
</table>
And this is my script but it's not working
$(document).ready(function () {
$('#CheckBox1').removeAttr('checked');
$('#CheckBox2').removeAttr('checked');
$('#CheckBox3').removeAttr('checked');
$('#CheckBox4').removeAttr('checked');
$('#Panel2').hide();
$('#Panel1').change(function () {
if (this.checked) {
$('#Panel2').show();
}
else {
$('#Panel2').hide();
}
});
});
Help please
Using jQuery you can compare the checked checkboxes vs all checkboxes inside Panel1 like this:
if($("#Panel1 input[type=checkbox]:checked").length === $("#Panel1 input[type=checkbox]").length){
$('#Panel2').show();
}else{
$('#Panel2').hide();
}

How can i get an element id inside a asp repeater with javascript. I am trying to get the ID of the RadioButtons

I have a table and inside the table i have an asp repeater.
<table id="repeaterTable">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<b>Not Feasible:</b> <asp:RadioButton ID="notfeasibleRadioBtn" runat="server"/> <b>Feasible:</b> <asp:RadioButton ID="feasibleRadioBtn" runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

showing two repeaters at the same div but once at a time

I would like to show to two different repeaters in same div but once at a time.
<div id="tab1" class="tab_content">
<div class="comment1">
<div class="comments_header">Our Previous Comments</div>
<div class="prev_comments">
<asp:Panel ID="Panel2" runat="server">
<asp:Repeater ID="rptcomment" runat="server" >
<HeaderTemplate>
<table style="background-color:antiquewhite; width:600px; cellpadding="0" >
<tr >
<td colspan="2"></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:5px; border-bottom:dotted" >
<img src="../images/prople.jpg" style="height: 77px; width: 72px" />
</td>
<td style=" border-bottom:dotted">
<asp:Label ID="lblname" runat="server" Text='<%#Eval("fullname") %>' />
on
<asp:Label ID="Label2" runat="server" Text='<%#Eval("datetime") %>' Font-Bold="true"/>
<br />
<asp:Label ID="lblcomment" runat="server" Text='<%#Eval("comment") %>'/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
<asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical" Height="457px" Width="607px">
<asp:Repeater ID="RepterDetails" runat="server" >
<HeaderTemplate>
<table style="background-color:darkturquoise; width:600px; cellpadding="0">
<tr >
<td colspan="2">
<center> <b>Our Previous Comments</b></center>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:5px; border-bottom:dotted" >
<img src="http://localhost:1411/images/prople.jpg" style="height: 77px; width: 72px" />
</td>
<td style=" border-bottom:dotted">
<asp:Label ID="lblname" runat="server" Text='<%#Eval("fullname") %>' />
on
<asp:Label ID="Label2" runat="server" Text='<%#Eval("datetime") %>' Font-Bold="true"/>
<br />
<asp:Label ID="lblcomment" runat="server" Text='<%#Eval("comment") %>'/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
<center>
<asp:Label ID="Label1" runat="server" Font-Bold="True" />
<asp:HyperLink ID="linkPrev" runat="server">Previous Page</asp:HyperLink>
<asp:HyperLink ID="linkNext" runat="server">Next Page</asp:HyperLink>
</center>
<div class="clear"></div>
</div>
</div>
</div>
In the above code when first page loads I would like to show repeater which are in panel2 and when user clicks on link previous comment I would like to show repeater of panel1 only but in the same div and same page.How to solve this problem?
Since you have each repeater inside an asp:Panel, this will be as easy as set the Visible attribute of the pertinent panel to false.
You can also archive this by using CSS styles with display: none; or visibility: hidden.

2 jQuery script on same page

I have 2 jQuery script in one page jQuery Dialog and jQuery slideToggle inside the dialog box, jQuery dialog is working but after hitting button to open jQuery Dialog inside the dialog box there will be a button to slideToggle a div but its not working I tried to move slideToggle outside the dialog and it works. I don't know whats going on inside the dialog box if someone can help me to solve my problem
jQuery Dialog
<script type="text/javascript">
$(function () {
$("#dialog").dialog({
appendTo: "form",
autoOpen: false,
width: 630,
height: 700,
draggable: false,
resizable: false,
modal: true
});
$("#btnaddnew").click(function () {
$("#dialog").dialog("open");
return false;
});
});
</script>
jQuery slideToggle
<script type="text/javascript">
$(document).ready(function () {
$("#Div1").hide();
$("#Button1").click(function () {
$("#Div1").slideToggle();
return false;
});
});
</script>
dialog div + slideToggle div inside the jQuery dialog
<div id="dialog" title="Classification">
<asp:UpdatePanel ID="addpanel" runat="server">
<ContentTemplate>
<table>
<tr>
<td><div id="registerform">
<table align="center" style="margin-top:10px" width="600">
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Selected="True">Choose Classification</asp:ListItem>
<asp:ListItem Value="Resident">Resident</asp:ListItem>
<asp:ListItem Value="Business">Business</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<table>
<tr>
<td><div id="divresident" runat="server" visible="false">
<table style="margin-top:10px; margin-bottom:10px">
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbAddress" runat="server" Text="Address"></asp:Label></td>
<td width="300"><asp:TextBox ID="txtAddress" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align:left"><asp:Label ID="lbUserEntry" runat="server" Text="Number of House occupant"></asp:Label></td>
<td><asp:TextBox ID="txtUserEntry" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align:left"><asp:Button ID="btnAddOccupant" runat="server" Text="+" />
<asp:Label ID="lbres5" runat="server" Text="Add Occupant"></asp:Label></td>
</tr>
<tr>
<td>
<div id="divOccupantProfile" style="display: none">
<asp:Label ID="OPfamilyname" runat="server" Text="Family Name"></asp:Label>
<asp:TextBox ID="textOPfamilyname" runat="server"></asp:TextBox><br />
<asp:Label ID="OPfirstname" runat="server" Text="First Name"></asp:Label>
<asp:TextBox ID="textOPfirstname" runat="server"></asp:TextBox><br />
<asp:Label ID="OPmiddlename" runat="server" Text="Middle Name"></asp:Label>
<asp:TextBox ID="textOPmiddlename" runat="server"></asp:TextBox><br />
<asp:Label ID="OPmaritalstatus" runat="server" Text="Marital Status"></asp:Label>
<asp:DropDownList ID="ddlOPmaritalstatus" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>Married</asp:ListItem>
<asp:ListItem>Single</asp:ListItem>
<asp:ListItem>Divorced</asp:ListItem>
</asp:DropDownList><br />
<asp:Label ID="OPoccupation" runat="server" Text="Occupation"></asp:Label>
<asp:TextBox ID="textOPoccupation" runat="server"></asp:TextBox><br />
<asp:Label ID="OPrelationship" runat="server" Text="Relationship"></asp:Label>
<asp:DropDownList ID="ddlOPrelationship" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>Wife</asp:ListItem>
<asp:ListItem>Daughter</asp:ListItem>
<asp:ListItem>Son</asp:ListItem>
<asp:ListItem>Father</asp:ListItem>
<asp:ListItem>Mother</asp:ListItem>
<asp:ListItem>House helper</asp:ListItem>
<asp:ListItem>Driver</asp:ListItem>
</asp:DropDownList>
</div>
<div id="holder">
</div>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
<table>
<tr>
<td><div id="divbusiness" runat="server" visible="false">
<table width="600" style="margin-top:10px; margin-bottom:10px">
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbbus1" runat="server" Text="Registered Business Name" ></asp:Label></td>
<td width="300"><asp:TextBox ID="txtbus2" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbbus3" runat="server" Text="Address"></asp:Label></td>
<td width="300"><asp:TextBox ID="txtbus4" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbbus5" runat="server" Text="Structure"></asp:Label></td>
<td width="300"> </td>
</tr>
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbbus6" runat="server" Text="SEC No./DTI number"></asp:Label></td>
<td width="300"><asp:TextBox ID="txtbus7" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td width="300" style="text-align:left"><asp:Label ID="lbbus8" runat="server" Text="Nature of Business"></asp:Label></td>
<td width="300"><asp:TextBox ID="txtbus9" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align:left">
<div>
<asp:Button ID="Button1" runat="server" Text="+" />
<asp:Label ID="Label1" runat="server" Text="Add Phone"></asp:Label>
<div id="Div1" style="display: none">
<asp:Label ID="Label2" runat="server" Text="Landline work"></asp:Label>
<asp:TextBox ID="TextBox1" class="basetxt" runat="server" ></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Handphone personal" ></asp:Label>
<asp:TextBox ID="TextBox2" class="basetxt" runat="server"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Handphone work"></asp:Label>
<asp:TextBox ID="TextBox3" class="basetxt" runat="server"></asp:TextBox>
</div>
</div>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
.click won't work on later loaded elements, try it like this, replace:
$("#Button1").click(function () {
With:
$("body").on('click', '#Button1', function() {

Categories