【发布时间】:2010-10-17 19:48:55
【问题描述】:
我正在尝试更新页面上的所有文本框,以将它们转换为如下标签:
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,同样,如果选中#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 />
问题是,当页面加载时,它们可以正常工作,但如果调用更新面板的 update() 函数,它们似乎会失去与应该调用的 javascript 的连接。同样,任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: asp.net javascript updatepanel