在检查完CheckBox之后,我将在位于updatepanel之外的TextBox中显示一些文本,但我无法使其工作。请帮帮我好吗?
下面是我的代码:
<asp:UpdatePanel runat="server" ID="uplMaster">
<ContentTemplate>
<asp:CheckBox ID="cbShowText" runat="server" Text="Show Some Text" AutoPostBack="true"
OnCheckedChanged="cbShowText_CheckedChanged" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="txtBox" Text="Empty" runat="server" />
代码隐藏:
protected void cbShowText_CheckedChanged(object sender, EventArgs e)
{
txtBox.Text = "Some Text";
}
提前感谢:D
附注:正如你可能已经猜到的那样,我的问题和我的类似,这就是为什么我不想把TextBox放在UpdatePanel中
发布于 2010-05-22 13:58:12
我将TextBox放在另一个UpdatePanel中,然后调用更新方法:
这是我的新代码:
<asp:UpdatePanel runat="server" ID="uplMaster" UpdateMode="Always">
<ContentTemplate>
<asp:CheckBox ID="cbShowText" runat="server" Text="Show Some Text" AutoPostBack="true"
OnCheckedChanged="cbShowText_CheckedChanged" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="uplDetail" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtBox" Text="Empty" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
代码隐藏:
protected void cbShowText_CheckedChanged(object sender, EventArgs e)
{
txtBox.Text = "Some Text";
uplDetail.Update();
}
希望这能有所帮助
发布于 2010-05-19 18:49:41
文本框也必须在更新面板中。
*编辑:
很抱歉,我没有正确阅读您的问题。也许编写一个javascript函数,然后从code后台调用该函数?
发布于 2015-08-22 02:14:24
我知道这个问题已经有一段时间了,但这是我所做的。就像@bla所说的那样,编写一个javascript函数并在后台代码中调用它。
所以在你的checked changed中调用这个。changeText是页面上的一个javascript函数,位于页眉或脚本文件中。
protected void cbShowText_CheckedChanged(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "Show Different Text", "changeText();", true);
}
示例Javascript。仅在checked changed事件从代码后台激发时调用。
<script type="text/javascript">
function changeText() {
var txt= document.getElementById('<%= txtBox.ClientID %>');
var chk = document.getElementById('<%= cbShowText.ClientID %>');
if (chk.checked === true) {
txt.Text = "Something";
} else {
txt.Text = "Somethingelse";
}
}
</script>
希望这对某些人有帮助。
https://stackoverflow.com/questions/2864692
复制相似问题