将项目添加到UpdatePanel中的列表框 [英] Add Items To ListBox In UpdatePanel

查看:74
本文介绍了将项目添加到UpdatePanel中的列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Listbox,它存在于ASP.NET Web窗体的UpdatePanel中.在UpdatePanel内部,还有一个Button,它将一堆ListItem添加到Listbox中,该PostBackTrigger如下所示:

I have a Listbox that exists in an UpdatePanel on an ASP.NET webform. Also inside the UpdatePanel, exists a Button that adds a bunch of ListItem's to the Listbox, this PostBackTrigger as shown below:

<asp:UpdatePanel ID="updSection6" runat="server">
    <ContentTemplate>
        <asp:LinkButton Text="Run Scan" ID="btnEditSectionStory6" runat="server" OnClick="btnRunScan_Click" />
        <br />
           <asp:ListBox ID="lbLog" runat="server" Height="263px" Width="747px"></asp:ListBox>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnEditSectionStory6" />
    </Triggers>
</asp:UpdatePanel>

我在点击事件中添加了项目:

I add items in the click event:

 protected void btnRunScan_Click(object sender, EventArgs e)
        {
            lbLog.Items.Add("Scan Beginning...");

.....hundreds of other items
}

将这些项目添加到ListBox,但是这是在整个btnRunScan_Click方法运行之后,而不是在每个事件发生时添加它们(因此,用户可以在操作发生时接收消息).我在UpdatePanel上缺少属性或其他内容吗?

The items are added to the ListBox, however it is after the entire btnRunScan_Click method is run, rather than adding them as each event occurs (So the user can receive messages as the actions occur). Am I missing an attribute or something on the UpdatePanel?

TIA

推荐答案

要添加项目而不刷新页面或防止调用循环事件,请使用以下代码,并消除触发器内的postBackTrigger.请使用经过测试的代码对我有效.还可以使用scriptManager来防止异常,以使用updatePanel

To Add Items without refreshing page or prevent from calling the cyclic events use following code and eliminate postBackTrigger inside the Trigger.Use following code that is tested working for me.Also use the scriptManager to prevent from exception over to use the updatePanel

.aspx设计文件

<asp:ScriptManager runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="updSection6" runat="server">
            <Triggers>
            </Triggers>
        <ContentTemplate>
            <asp:LinkButton Text="Run Scan" ID="btnEditSectionStory6" runat="server" OnClick="btnRunScan_Click" />
            <br />
               <asp:ListBox ID="lbLog" runat="server" Height="263px" Width="747px"></asp:ListBox>
        </ContentTemplate>
    </asp:UpdatePanel>

.cs文件

protected void btnRunScan_Click(object sender, EventArgs e)
{
    lbLog.Items.Add("Scan Beginning...");
}

就像其他人提到的那样,您也可以使用带有ajax的jquery在客户端进行编码以实现这一目标.

As other also mention you can also use jquery with ajax to code over the client side to do this one.

这篇关于将项目添加到UpdatePanel中的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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