如何在复选框cikck上停止重新加载页面 [英] How to stop reloading page on checkbox cikck
本文介绍了如何在复选框cikck上停止重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
当我选中复选框(AddToCartCheckBox)我的页面重新加载时我遇到了问题
我的代码...
aspx代码......
Dear Friends,
I am facing problem while i check the checkbox (AddToCartCheckBox) my page get reloaded
My Code...
aspx code...
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div class="productdisplayStyle">
<asp:Repeater ID="ProductList" runat="server">
<ItemTemplate>
.....
.......
.....
.......
<asp:CheckBox runat="server" ID="AddToCartCheckBox" Text=" Add To Cart" AutoPostBack="true" OnCheckedChanged="AddToCartCheckBox_CheckedChanged" />
</ItemTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>
< br $> b $ b
.cs代码
.cs code
protected void AddToCartCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (sender != null)
{
CheckBox checkbox = (CheckBox)sender;
RepeaterItem item = (RepeaterItem)checkbox.NamingContainer;
Label idlbl =(Label)item.FindControl("ItemIdLbl");
int id =Convert.ToInt32(idlbl.Text);
if (checkbox.Checked)
{
Cart cart = (Session["ShoppingCart"] != null) ? (Cart)Session["ShoppingCart"] : new Cart();
Cart cartList = (Cart)Session["ShoppingCart"];
if (cartList == null)
{
cartList = new Cart();
}
cartList.Add(id, 1);
Session["count"] = cartList.ItemsInCart.Count();
Session["ShoppingCart"] = cartList;
Session["total"] = cartList.CartTotalAmount;
loadUserControl();
}
else
{
Cart cart = (Session["ShoppingCart"] != null) ? (Cart)Session["ShoppingCart"] : new Cart();
Cart cartList = (Cart)Session["ShoppingCart"];
if (cartList == null)
{
cartList = new Cart();
}
cartList.Remove(id);
Session["count"] = cartList.ItemsInCart.Count();
Session["ShoppingCart"] = cartList;
Session["total"] = cartList.CartTotalAmount;
loadUserControl();
}
}
推荐答案
确保您的复选框位于UpdatePanel内..
Make sure your checkbox is inside the UpdatePanel..
这篇关于如何在复选框cikck上停止重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文