Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 循环使用UpdatePanel中的控件,并访问javascript_Asp.net_Javascript_Updatepanel - Fatal编程技术网

Asp.net 循环使用UpdatePanel中的控件,并访问javascript

Asp.net 循环使用UpdatePanel中的控件,并访问javascript,asp.net,javascript,updatepanel,Asp.net,Javascript,Updatepanel,我正在尝试更新页面上的所有文本框,以便将它们转换为标签,如下所示: foreach (Control ctrl in masterform.Controls) { if (ctrl.GetType() == typeof(TextBox)) { TextBox t = ctrl as TextBox; t.ReadOnly = true; t.BackColor = transparent; t.BorderWidt

我正在尝试更新页面上的所有文本框,以便将它们转换为标签,如下所示:

foreach (Control ctrl in masterform.Controls)
{
    if (ctrl.GetType() == typeof(TextBox))
    {
        TextBox t = ctrl as TextBox;
        t.ReadOnly = true;
        t.BackColor = transparent;
        t.BorderWidth = 0;
    }
}
不幸的是,我用一个更新面板包围了所有的文本框,无法再访问它们。所以我试过这个:

foreach (Control ctrl in masterform.Controls)
{
    if (ctrl is UpdatePanel)
    {
        UpdatePanel s = ctrl as UpdatePanel;
        if (s == PartPanel)
        {
            foreach (Control ctrl2 in s.Controls)
            {
                if (ctrl2 is TextBox)
                {
                    TextBox t = ctrl2 as TextBox;
                    t.ReadOnly = true;
                    t.BackColor = transparent;
                    t.BorderWidth = 0;
                }
            }
        }
    }
}
这只是显示面板控件计数为1,但其中有大量的文本框控件。任何帮助都将不胜感激

此外,我还有一些相互排斥的复选框,它们的工作原理如下:如果选中了#1,则无法选中#2或#3,并且像wise一样,如果选中了#2或#3,则无法选中#1。这意味着,如果勾选了#2和/或#3,用户勾选了#1,#2和#3,那么#1被勾选,而用户勾选了#2和/或#3,那么#1将被勾选。我编写了以下函数来处理该问题,只要更新面板不更新,它就可以工作:

var objChkd;
$(document).ready(function() 
{
    $('.mutuallyexclusive1').click(function () 
    {
        checkedState = $(this).attr('checked');
        $('.mutuallyexclusive2:checked').each(function () 
        {
            $(this).attr('checked', false);
        });
        $(this).attr('checked', checkedState);
    });
    $('.mutuallyexclusive2').click(function () 
    {
        checkedState = $(this).attr('checked');
        $('.mutuallyexclusive1:checked').each(function () 
        {
            $(this).attr('checked', false);
        });
        $(this).attr('checked', checkedState);
    });
});  

<input id="Chk1" type="checkbox" runat="server" class="mutuallyexclusive1" /><br />
<input id="Chk2" type="checkbox"  runat="server" class="mutuallyexclusive2" /><br />
<input id="Chk3" type="checkbox" runat="server" class="mutuallyexclusive2" /><br />
var objChkd;
$(文档).ready(函数()
{
$('.mutuallyexclusive1')。单击(函数()
{
checkedState=$(this.attr('checked');
$('.mutuallyexclusive2:checked')。每个(函数()
{
$(this.attr('checked',false);
});
$(this.attr('checked',checkedState));
});
$('.mutuallyexclusive2')。单击(函数()
{
checkedState=$(this.attr('checked');
$('.mutuallyexclusive1:checked')。每个(函数()
{
$(this.attr('checked',false);
});
$(this.attr('checked',checkedState));
});
});  




问题是,当加载页面时,它们工作正常,但如果调用了更新面板的update()函数,它们似乎会失去与本应调用的javascript的连接。再次感谢您的帮助。谢谢。

对于您的UpdatePanel,请尝试以下操作以递归方式查找您的文本框并进行更新:

void DisableTextBoxes(Control parent)
{
    foreach (Control ctrl in parent.Controls)
    {
        TextBox t = ctrl as TextBox;
        if (t != null)
        {
            t.ReadOnly = true;
            t.BackColor = transparent;
            t.BorderWidth = 0;
        }
        else
        {
            DisableTextBoxes(ctrl);
        }
    }
}

DisableTextBoxes(masterform);

对于复选框,脚本在页面加载时执行,此时事件处理程序绑定到控件。如果复选框是DOM的一部分,在
UpdatePanel
刷新期间未重新加载完整的页面,则事件处理程序不再绑定到它们(它们是新的元素)。部分刷新页面后,您需要再次绑定事件。

对于UpdatePanel,请尝试递归查找文本框并更新它们:

void DisableTextBoxes(Control parent)
{
    foreach (Control ctrl in parent.Controls)
    {
        TextBox t = ctrl as TextBox;
        if (t != null)
        {
            t.ReadOnly = true;
            t.BackColor = transparent;
            t.BorderWidth = 0;
        }
        else
        {
            DisableTextBoxes(ctrl);
        }
    }
}

DisableTextBoxes(masterform);
对于复选框,脚本在页面加载时执行,此时事件处理程序绑定到控件。如果复选框是DOM的一部分,在
UpdatePanel
刷新期间未重新加载完整的页面,则事件处理程序不再绑定到它们(它们是新的元素)。部分刷新页面后,需要再次绑定事件