Get checkboxes in repeater header template - asp.net

I need to access some checkboxes that are inside the header template of my repeater.
Actually they are outside of it and in the code behind they are accessed using the keyword "this". I cannot change all the code and i must mantain the same logic. The issue is that if i move the checkboxes inside the header of the repeater, i cannot find them using "this".
I've something like this:
<div id="containerListNotify" style="padding-left: 5px;">
<asp:UpdatePanel ID="UpdatePanelRepListNotify" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
<ContentTemplate>
<asp:HiddenField ID="iconsHiddenField" runat="server" ClientIDMode="Static" />
<asp:Repeater ID="repListNotify" runat="server" OnItemCommand="RepListNotify_ItemCommand"
OnItemDataBound="RepListNotify_ItemCreated">
<HeaderTemplate>
<table id="tableCentroMessaggi" class="table table-hover">
<thead>
<tr id="HeaderMessaggi">
<th>
<%--<asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' />--%>
<div class="dropdown">
<button onclick="openCloseDocFascDropdown()" class="dropbtn"><asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' /><b class="caret"></b></button>
<div id="docFascDropdown" class="dropdown-content">
<ul>
<li>
<asp:CheckBox ID="IndexCheckDoc" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckProj" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckOther" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
</ul>
</div>
</div>
</th>
<th>
The important thing is that i need to access them even in private methods and not only in event methods.
I hope that there is a solution to this. I guess i can use "FindControl".
This .aspx uses a MasterPage.
Thanks in advance.

If you want to access Controls that are inside another control like Repeater, GridView etc. you're gonna have to use FindControl with and item/row index. Where you access them does not matter.
CheckBox IndexCheckDoc = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckDoc") as CheckBox;
CheckBox IndexCheckProj = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckProj") as CheckBox;
CheckBox IndexCheckOther = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckOther") as CheckBox;

Related

How to include html inside anchor tag in Sitecore

I have a situation where there is HTML inside an anchor tag. And the author should be able to edit both the anchor (href) & other fields.
aspx:
<asp:Repeater ID="rpEvents" runat="server" ItemType="Sitecore.Data.Items.Item">
<HeaderTemplate>
<div class="col-md-3">
</HeaderTemplate>
<ItemTemplate>
<a href="offers/spring.html">
<sc:Image runat="server" Field="offer image" Item=<%#Container.DataItem%> />
<h3><sc:Text runat="server" Field="Offer Title" Item=<%#Container.DataItem%> /></h3>
</a>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
I would do this by turning the <a> into <asp:Hyperlink> & assigning its NavigateURL property from code behind, but then the author cannot edit it in experience editor.
How is this done in Sitecore.
You can wrap the other HTML elements using the Link field, which will allow all fields to continue to be edited from the Experience Editor:
<ItemTemplate>
<sc:Link Field="Offer Link" Item="<%# Container.DataItem %>" runat="server">
<sc:Image Field="Offer Title" Item="<%# Container.DataItem %>" runat="server" />
<h3><sc:Text Field="offer image" Item="<%# Container.DataItem %>" runat="server" /></h3>
</sc:Link>
</ItemTemplate>
The Link can still be set, the image changed or the separate text field edited:
An option is to use the sc:EditFrame inside a repeater, that looks like:
<asp:Repeater runat="server" ID="AccordionRowRepeater">
<ItemTemplate>
<my:AccordionRow runat="server" ID="AccordionRowItem" RowItem="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
And the Row control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AccordionRow.ascx.cs" Inherits="mynamespace.Controls.AccordionRow" %>
<sc:EditFrame id="EditAccordionItem" runat="server" Buttons="/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Accordion Item">
<li class="<%= LiClass %>">
<a class="trigger" href="#"><sc:Text runat="server" ID="ItemTitle"/></a>
<div class="collapsible">
<sc:Text runat="server" ID="ItemText" />
</div>
</li>
</sc:EditFrame>
And add a Field Editor Button to the Edit Frame Buttons
More about this Accordion example see User friendly developing with the Sitecore Experience Editor
Or, I often use this simple solution. It also give you the opportunity to display some help text to the content editor.
<div runat="server" id="PageditorDiv" Visible="False">
URl: <sc:Link runat="server" ID="link"/>
</div>
And in the code Behind.
if (Sitecore.Context.PageMode.IsPageEditor)
{
PageditorDiv.Visible = true;
}

New line pressing "Return" key with asp:TextBox

I have an asp:TextBox in an ajax popup panel. I've searched for a way to make a new line when the user presses the "Enter/Return" key, but nothing has worked so far.
Here is my TextBox:
<asp:TextBox ID="CommentaireSaveTxt" MaxLength="4999" TextMode="MultiLine"
Width="250px" Height="100px" runat="server" />
I've read that sometimes the enter key defaults to a button without any indication that it will do so, but none of my ajax panel's buttons events are firing. As far as I know, nothing happens at all. I suspect there might be some kind of problem with my textbox being in the panel.
Here is my AJAX:
<ajaxToolkit:ModalPopupExtender ID="btnSauvegarder_ModalPopupExtender"
runat="server" TargetControlID="DummySauvegarder"
PopupControlID="btnSauvegarder_ModalPopupExtender_PNL"
CancelControlID="ButtonCancel"
BackgroundCssClass="modalBackground"
Enabled="True" DynamicServicePath="" />
<asp:Panel ID="btnSauvegarder_ModalPopupExtender_PNL"
Style="display: none;"
CssClass="modalPNL"
runat="server"
meta:resourcekey="btnSauvegarder_ModalPopupExtender_PNLResource1">
<table border="0">
<tr>
<td>
<img src="..\Images\IconQuestion.png" alt="Question" />
<asp:TextBox ID="CommentaireSaveTxt" MaxLength="4999" Rows="50"
TextMode="MultiLine" Width="250px"
Height="100px" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMessageSauvegarder" runat="server"
meta:resourcekey="lblMessageSauvegarderResource1">
</asp:Label>
</td>
</tr>
</table>
<div style="text-align: right;">
<asp:Button ID="ButtonOkSauvegarder" runat="server" Text="OK"
OnClick="ButtonOkSauvegarder_Click"
meta:resourcekey="ButtonOkDeleteResource1" />
<asp:Button ID="ButtonCancelSauvegarder" runat="server" Text="Cancel"
meta:resourcekey="ButtonCancelResource2" />
</div>
</asp:Panel>
EDIT :
After testing...
For some reason, it doesn't work anywhere in my page. When looking at the generated html code from the browser, the textarea does not have any property for "AcceptsReturn" to true. I don't know if that can help anyone in finding the trouble.
My whole page is contained into UpdatePanel and ContentTemplate if that has any matters. I really am out of clue with what my problem is. I tested with a partner and he has no problem making it work in his projet (another website).

Add checkboxlist item onclick of another checkbox

I'm just wondering if there's a way to add a new checkbox item to an existing asp:checkboxlist control, when another checkbox is checked, without having to do a full postback of the page. Whether it's with javascript, jquery, ajax. Just wondering how (if at all) I can do something like this.
I've been doing some research and it appears I can do a partial postback using an asp:UpdatePanel. I've never used one of these before. Does anyone have an example of how they can be used? Here's what I have, but it's still doing a full postback
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<tr>
<td width="50%">
<asp:CheckBox runat="server" ID="chkEnglish" Font-Bold="true" TextAlign="Right" Text=" English" />
</td>
<asp:Panel runat="server" ID="pnlTopLanguages">
<td rowspan="3" valign="top">
<asp:CheckBoxList ID="chkTopLanguages" CssClass="cb chkTopLangs" TextAlign="Right" runat="server" />
<asp:TextBox runat="server" ID="txtOtherLanguages" onkeyup="SetButtonStatus(this)" onclick="return clearLanguageSearchText()" Text="Other Languages..."></asp:TextBox>
<asp:Button runat="server" ID="btnAddLang" Text="Add" OnClientClick="return CopyOtherLangs()" Enabled="false" /><br /><br />
<asp:CheckBox runat="server" ID="chkManyOtherLanguages" CssClass="cb" Font-Bold="true" Text="Many other languages" />
<cc3:AutoCompleteExtender ID="aceSearch" runat="server" MinimumPrefixLength="1" TargetControlID="txtOtherLanguages"
ServicePath="~/controls/wsCommunity.asmx" ServiceMethod="GetLanguageCompletionList"></cc3:AutoCompleteExtender>
</td>
</asp:Panel>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
Building off Adils answer...to add a checkbox on check of another one, you can use:
$(".classOfCheckboxList").change(function() {
$(this).append("<input type='checkbox' id='newbox' class='currentclass' value='someval' />");
});
As Adil said, this new dynamically added box wont be accessible in the code-behind.

How to get the parent item index inside child repeater?

I have nested repeaters like this:
<asp:Repeater ID="rptQuestoes" runat="server">
<HeaderTemplate>
<ol class="orderedList">
</HeaderTemplate>
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem, "QuestionName")%>
<asp:Repeater ID="rptAlternativas" DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>' runat="server">
<HeaderTemplate>
<ul style="list-style-type: none">
</HeaderTemplate>
<ItemTemplate>
<li>
<input id="rb" type="radio" name='ITEM_INDEX_HERE' value='<%#Container.DataItem("AlternativeID")%>' /><%#Container.DataItem("AlternativeName")%>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>
I want to print the parent item index inside the child repeater (rptAlternativas) in VB right in ITEM_INDEX_HERE marker. How can I achieve this?
I hope someone can give you a better answer than this, but I would consider adding a property to your "Quentionario" sub elements.
<asp:Repeater ID="rptAlternativas"
DataSource='<%# Container.DataItem.Row.GetChildRows("Questionario") %>'
runat="server">
Can you add a question id to each of these objects? You're already binding to their AlternativeId in your radio button, adding a question id to these objects would let you do simply:
<input id="rb" type="radio" name='<%#Container.DataItem("QuestionId")%>' value='<%#Container.DataItem("AlternativeID")%>' />
Even if these objects are auto-generated from an ORM, you should be able to add the property in via a partial class, and then just set the appropriate values in a simple loop.

ASP.NET Login control Layout template failuretext

I have a login control with the following markup:
<asp:Login ID="ScrapLogin" runat="server" FailureText="Brugeren findes ikke eller adgangskoden er forkert!" RenderOuterTable="false">
<LayoutTemplate>
<ul class="form">
<li>
<asp:Label AssociatedControlID="UserName" runat="server" Text="Brugernavn:" />
<asp:TextBox ID="UserName" runat="server" />
</li>
<li>
<asp:Label AssociatedControlID="Password" runat="server" Text="Password:" />
<asp:TextBox ID="Password" runat="server" TextMode="Password" />
</li>
</ul>
<asp:Button ID="Login" runat="server" Text="Log ind!" />
*<asp:Literal ID="FailureText" runat="server" EnableViewState="false" />*
</LayoutTemplate>
The problem is, the FailureText is never shown, even when I enter a wrong username or password. It just reloads the page. Do I need to trigger this myself somehow? If I don't specify the LayoutTemplate, it shows the text as it should (although it renders with tons of tables :).
Thanks in advance! :)
Hehe, I just found out that it isn't enough to just give the button an Id of "Login". The CommandName has to be set to "Login". I'm just leaving the solution here if anyone else should stumple upon this problem.

Resources