Here is the code. I have also tried using oncommad property but still no luck.
These imagebuttons are the part of asp:repeater.
I am using this for online shop.
<span class="col col-xs-12 col-md-3">
<asp:RegularExpressionValidator ID="QuantityRegularExpressionValidator" runat="server"
ValidationExpression="\d+" ControlToValidate="QuantityTextBox" ErrorMessage="*"
Display="None"></asp:RegularExpressionValidator>
<asp:RangeValidator ID="QuantityRangeValidator" runat="server"
ErrorMessage="RangeValidator" ControlToValidate="QuantityTextBox"
MaximumValue="9999" MinimumValue="1" Display="None"></asp:RangeValidator>
<asp:ImageButton ID="UpdateItemQuantityImageButton" runat="server"
ImageUrl="~/Responsive/custom/images/Shop/refreshItem.png"
Height="19" OnClick="UpdateItemQuantityImageButton_Click"
CssClass="shopCartListButton" />
<asp:ImageButton ID="DeleteItemImageButton" runat="server"
ImageUrl="~/Responsive/custom/images/Shop/deleteItemFromCart.png"
Height="19" OnClick="DeleteItemImageButton_Click" CssClass="shopCartListButton" />
</span>
Code Behind is given below. I have added the page load and page init event, if that help to find out solution.
Thanks in advance.
protected void Page_Init(object sender, EventArgs e)
{
siteId = Master.siteId;
//check if this page is empty.
if (Master.pageId == Guid.Empty)
{
//this page is unknown, so get the page based on the pageTypeId.
thisPage = DAL.DataClasses.Page.GetPageForSite(pageTypeId, siteId);
}
try
{
shopCartId = long.Parse(Session["shopCartId"].ToString());
thisShopCart = DAL.DataClasses.ShopCart.GetObjectById(shopCartId);
thisShop = thisShopCart.Shop;
}
catch
{
//can't get a product.
//go to the shop front.
thisShop = DAL.DataClasses.Shop.GetDefaultShopForSite(siteId);
if (thisShop != null)
{
Response.Redirect(DAL.DataClasses.Shop.GetDetailPageURL(thisShop.ShopId, siteId));
}
else
{
//no shop for this site. redirect to home page.
Response.Redirect(Master.thisSite.WebsiteURL);
}
}
DisplayContent();
}
protected void Page_Load(object sender, EventArgs e)
{
TransactionTotalLiteral.Text = DAL.DataClasses.ShopCart.CalculateCartTotal(shopCartId).ToString("C");
}
public void DisplayContent()
{
// PageHeadingLiteral.Text = thisShop.Name;
IList<ORM.Shopcartitem> shopCartItemList = DAL.DataClasses.ShopCart.GetItemsInCart(shopCartId);
if (shopCartItemList.Count() == 0)
{
CheckoutButton.Visible = false;
EmptyLiteral.Visible = true;
}
else
{
EmptyLiteral.Visible = false;
}
ShopCartRepeater.DataSource = shopCartItemList;
ShopCartRepeater.DataBind();
}
protected void DeleteItemImageButton_Click(object sender, ImageClickEventArgs e)
{
ImageButton thisImageButton = (ImageButton)sender;
RepeaterItem thisRepeaterItem = (RepeaterItem)thisImageButton.Parent;
Repeater thisRepeater = (Repeater)thisRepeaterItem.Parent;
HiddenField ShopCartItemIdHiddenField = (HiddenField)thisRepeaterItem
.FindControl("ShopCartItemIdHiddenField");
TextBox QuantityTextBox = (TextBox)thisRepeaterItem.FindControl("QuantityTextBox");
long shopCartItemId = long.Parse(ShopCartItemIdHiddenField.Value);
DAL.DataClasses.ShopCart.DeleteItemFromCart(shopCartItemId);
TransactionTotalLiteral.Text = DAL.DataClasses.ShopCart.CalculateCartTotal(shopCartId)
.ToString("C");
DisplayContent();
}