【问题标题】:Not able to access the child control with in user control using javascript无法使用 javascript 在用户控件中访问子控件
【发布时间】:2011-04-27 02:36:21
【问题描述】:

我有一个用户控件“SettingsControl”,其中包含一个 ajax:CollapsiblePanelExtender,它又具有一个 GridView (gridView) 和复选框。在 GridView 之上,我们有两个链接按钮“全选”和“全部清除”。我已经写了启用全选并清除所有功能。全选应该通过调用编写在客户端 .aspx 文件上的以下 JavaScript 来选择网格中的所有行。

function SelectAll(chk)
{    
    //get reference of GridView control
    var grid = document.getElementById('<%= SettingsControl1.FindControl("gridView").ClientID %>');
    //variable to contain the cell of the grid
    var cell;

    if (grid.rows.length > 0)
    {
        //loop starts from 1. rows[0] points to the header.
        for (i=1; i<grid.rows.length; i++)
        {
            //get the reference of first column
            cell = grid.rows[i].cells[0];

            //loop according to the number of childNodes in the cell
            for (j=0; j<cell.childNodes.length; j++)
            {           
                //if childNode type is CheckBox                 
                if (cell.childNodes[j].type =="checkbox" && cell.childNodes[j].id.indexOf('chkSel')!=-1)
                {
                //assign the status of the Select All checkbox to the cell checkbox within the grid
                    cell.childNodes[j].checked = chk;
                }
            }
        }
    }
}

我无法在客户端访问用户控件或用户控件的任何元素。我不确定如何实现此功能。

.aspx 页面将用户控件调用为:

<uc1:SettingsControl ID="SettingsControl1" runat="server" />

请帮忙!!!!

【问题讨论】:

    标签: javascript gridview checkbox controls


    【解决方案1】:
    var grid = document.getElementById('SettingsControl1_gridView');
    

    对我有用。

    如果您在用户控件内执行脚本,则必须使用'SettingsControl1$gridView'

    希望这会帮助任何人......任何时候...... ;-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多