如何prevent页面被postbacked当我从一个列表框项目转移到其他 [英] How to prevent page being postbacked when i transfer item from one listbox to other

查看:91
本文介绍了如何prevent页面被postbacked当我从一个列表框项目转移到其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表框在我的按钮的应用程序点击我推的项目从一个列表框以外,在code正常工作,但它会导致回传,而我将项目从一个列表框到其他整页被再次加载,我怎么可以prevent这一点。

这将是code在我的aspx页面

 < D​​IV CLASS =BX1>
        <的Telerik:RadListBox ID =RadListBox1=服务器DataTextField =名称DataValueField =ID
             宽度=250像素>
        < /的Telerik:RadListBox>
        < / DIV>
       < D​​IV的风格=高度:7px的>< / DIV>
        < D​​IV CLASS =BX5>
         < ASP:ImageButton的ID =ImageButton1=服务器的ImageUrl =图片/ dwnArrow.png的OnClick =MoveDownClick/>
         < ASP:ImageButton的ID =ImageButton2=服务器的ImageUrl =图片/ uparrow.png的OnClick =MoveUpClick/>
       < / DIV>
         < D​​IV的风格=高度:7px的>< / DIV>

       < D​​IV CLASS =BX1>
        <的Telerik:RadListBox ID =RadListBox2=服务器DataTextField =名称
            DataValueField =IDWIDTH =250像素>
        < /的Telerik:RadListBox>
        < / DIV>
 

这是我的code背后列表框

 保护无效MoveDownClick(对象发件人,EventArgs的)
            {
                如果(RadListBox1.SelectedIndex℃,)
                {
                }
                其他
                {
                    RadListBox2.Items.Add(RadListBox1.SelectedItem);
                    RadListBox1.Items.Remove(RadListBox1.SelectedItem);
                    RadListBox2.SelectedItem.Selected = FALSE;
                }
            }
            保护无效MoveUpClick(对象发件人,EventArgs的)
            {
                如果(RadListBox2.SelectedIndex℃,)
                {

                }
                其他
                {

                    RadListBox1.Items.Add(RadListBox2.SelectedItem);
                    RadListBox2.Items.Remove(RadListBox2.SelectedItem);
                    RadListBox1.SelectedItem.Selected = FALSE;

                }

            }
 

解决方案

如果您的Visual Studio版本低于2008,那么首先从以下站点下载Ajax和安装:

HTTP://ajaxcontroltoolkit.$c$cplex.com/

添加引用System.Web.Extensions程序的DLL,然后你的初始&lt之后添加以下行,形式GT;标签:

 < ASP:的ScriptManager =服务器ID =SCRIPT1>< / ASP:ScriptManager的>
 

替换您code 在下面这段code与整个code,你已经写了上面的:

 < ASP:UpdatePanel中=服务器ID =U1>
<的ContentTemplate>
您的code
< /的ContentTemplate>
< / ASP:UpdatePanel的>
 

就这样,这将停止回发你的页面。

I have two listboxes in my application on button click i am pushing the item from one list box to other , the code works fine but it causes postback , while i move the item from one list box to other whole page is being loaded again , how i can prevent this .

This will be the code on my aspx page

 <div class="bx1">
        <telerik:RadListBox ID="RadListBox1" runat="server" DataTextField="Name" DataValueField="Id"
             Width="250px">
        </telerik:RadListBox>
        </div>
       <div style="height:7px"></div>
        <div class="bx5">
         <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/dwnArrow.png" OnClick="MoveDownClick" />
         <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="images/uparrow.png" OnClick="MoveUpClick" />
       </div>
         <div style="height:7px"></div>

       <div class="bx1">
        <telerik:RadListBox ID="RadListBox2" runat="server"   DataTextField="Name"
            DataValueField="Id" Width="250px" >
        </telerik:RadListBox>
        </div>

This is my code behind for listbox

 protected void MoveDownClick(object sender, EventArgs e)
            {
                if (RadListBox1.SelectedIndex < 0)
                {
                }
                else
                {
                    RadListBox2.Items.Add(RadListBox1.SelectedItem);
                    RadListBox1.Items.Remove(RadListBox1.SelectedItem);
                    RadListBox2.SelectedItem.Selected = false;
                }
            }
            protected void MoveUpClick(object sender, EventArgs e)
            {
                if (RadListBox2.SelectedIndex < 0)
                {

                }
                else
                {

                    RadListBox1.Items.Add(RadListBox2.SelectedItem);
                    RadListBox2.Items.Remove(RadListBox2.SelectedItem);
                    RadListBox1.SelectedItem.Selected = false;

                }

            }

解决方案

If your version of Visual Studio is less than 2008, then first download the ajax from the following site and install it:

http://ajaxcontroltoolkit.codeplex.com/

Add a reference to the System.Web.Extensions dll and then add the following line right after your opening <form> tag:

<asp:ScriptManager runat="server" ID="Script1"></asp:ScriptManager>

Replace the Your Code in following piece of code with your entire code that you have written above:

<asp:UpdatePanel runat="Server" ID="u1">
<ContentTemplate>
Your Code
</ContentTemplate>
</asp:UpdatePanel>

That's it, this will stop posting back your page.

这篇关于如何prevent页面被postbacked当我从一个列表框项目转移到其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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