JavaScript in a Repeater

MSTr

so i have a repeater that contains :

<table>
<tr>
    <td>
        <div class="divStyle">
            <asp:CheckBox ID="cbSelection" runat="server" AutoPostBack="true"/>
        </div>
        <div class="divStyle">                    
            <asp:Literal ID="ltlName" runat="server"></asp:Literal>
        </div>
        <div style="float:left; width:110px; margin-right:13px;">
            <asp:DropDownList ID="ddlMode" runat="server"></asp:DropDownList>
        </div>
        <div style="float:left; width:110px;">
            <asp:DropDownList ID="ddlQuantity" runat="server" 
             onChange="javascript:CheckPostBack();"></asp:DropDownList>
        </div>
    </td>
</tr>

what i want to do is as follows : each time the drodDown item is changed, i check if the check box is checked and if it's so i execute a method in the code behind.

so i created the following JavaScript :

<script>
function CheckPostBack() {
    var checkElt = document.getElementById(GetCheckBoxClientID());
    if (checkElt != null) {
        alert($(checkElt).prop('checked'));
        if ($(checkElt).prop('checked')) {
            var hdnBtn = document.getElementById(GetHiddenBtnClientID());
            hdnBtn.click();
        }
    }
}

hdnBtn is a button that i use to fire a postBack, GetCheckBoxClientID and GetHiddenBtnClientID are methods on the code behind injected onPageLoad so i can get the respective id of the check box and the HiddenButton.

the problem is that this methods didn't work, because the method is the same for all items so each test is done for the checkBox from the first item of the repeater.

MSTr

so, it take me a little bit to find a solution (ugly one in fact) i add an id to the div containig the checkBox and then used the DOM and navigate to the CheckBox which is in the same Row

<script type="text/javascript">
function CheckPostBack(sourceElt) {
    var DivCollection = sourceElt.parentNode.parentNode.getElementsByTagName("div");

    for (var i = 0; i < DivCollection.length; i++) {
        var oCurDiv = DivCollection[i];

        if (oCurDiv.id.indexOf('lnkContainer') >= 0) {
            var checkElt = (oCurDiv.firstElementChild || oCurDiv.firstChild)

            if (checkElt != null) {
                alert($(checkElt).prop('checked'));

                if ($(checkElt).prop('checked')) {
                    var hdnBtn = document.getElementById(GetHiddenBtnClientID());
                    hdnBtn.click();
                }
            }
        }
    }       
}

in fact i used the answer that i found on this link: How to access a Div inside a repeater using javascript

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to refresh Repeater after 1 minute with javascript?

From Dev

Javascript Array generated by ASP Repeater not updated

From Dev

Access asp element in a repeater via javascript

From Dev

getting controls inside a repeater in javascript function for validation

From Dev

asp.net repeater use template in javascript

From Dev

Access asp element in a repeater via javascript

From Dev

October CMS javascript event on backend repeater fields

From Dev

How to get text of a particular lable placed inside a repeater in javascript

From Dev

How to call javascript from code behind for Repeater control

From Dev

Not able to pass repeater Container.ItemIndex to javascript function as an argument

From Dev

How to get text of a particular lable placed inside a repeater in javascript

From Dev

Use repeater inside repeater

From Dev

Paging With Repeater

From Dev

Databind to a Repeater

From Dev

Find Repeater Nested Anywhere Inside Another Repeater

From Dev

Random Repeater in a Repeater Advanced Custom Fields

From Dev

how to get all elements of repeater under repeater

From Dev

How to Sum column in repeater

From Dev

If statement inside Repeater control

From Dev

Populate GridLayout with Repeater

From Dev

data repeater not showing image

From Dev

Virtual Repeater and Protractor

From Dev

User Control Inside Repeater

From Dev

What is Repeater Tasks process?

From Dev

Repeater access elements

From Dev

Get ClientId of control in Repeater

From Dev

Protractor - wait for repeater elements

From Dev

AngularJS - "Duplicates in a repeater not allowed"

From Dev

Index of a button inside a Repeater