如何在更新面板之外更新控件? [英] How to update a control outside of an updatepanel?

查看:61
本文介绍了如何在更新面板之外更新控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在检查CheckBox之后,我将在位于updatepanel外部的TextBox中显示一些文本,但是我无法使其工作.请帮帮我吗?

I am going to show some text in a TextBox, which is located outside of an updatepanel, after checking a CheckBox but I cannot make it work. please help me out ?

这是我的代码:

<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

P.S.您可能已经猜到了,我很像我的问题,这就是为什么我不想将TextBox放在UpdatePanel中的原因

P.S. As you might have guessed, I have resembled my problem and that is why I don't want to put the TextBox in the UpdatePanel

推荐答案

我将TextBox放在另一个UpdatePanel中,然后调用Update方法:

I put the TextBox in another UpdatePanel and then called the Update method:

这是我的新代码:

    <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();
        }

希望这会有所帮助

这篇关于如何在更新面板之外更新控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆