У меня есть кнопка ссылки в DataList в корзине, которая работает нормально. Как только они выберут продукт, если они обновят страницу sh, она снова запустит эту кнопку.
Код выглядит следующим образом:
protected void SelectPro1Bottom(object sender, EventArgs e)
{
DAL oDal = new DAL();
var btn = (LinkButton)sender;
//var btn = (HtmlButton)sender;
var item = (DataListItem)btn.NamingContainer; //RepeaterItem
int index = item.ItemIndex;
int quantity = 0;
GetSelected(index);
Session["amount"] = 1;
//pull in the quantity
Quantities = Session["formatQuantities"] as List<int>;
List<OrderUserTypeHolder> TempHolder = new List<OrderUserTypeHolder>();
OrderUserTypeHolder oh = new OrderUserTypeHolder();
TempHolder = Session["userTypeHolder"] as List<OrderUserTypeHolder>;
int userType = 0;
int hasAutoship = 0;
string country = "";
userType = TempHolder[0].UserType;
hasAutoship = TempHolder[0].HasAutoship;
country = TempHolder[0].Country;
ProductIdList.Clear();
using (oDal)
{
//dist
if (userType == 2 && hasAutoship == 1)
{
SqlDataReader rd = oDal.ProductsGetAllByDescLengthAutoReader(country);
while (rd.Read())
{
ProductIdList.Add(Convert.ToInt32(rd["productId"]));
}
}
else if (userType == 2)
{
SqlDataReader rd = oDal.ProductsGetAllByDescLengthDistReader(country);
while (rd.Read())
{
ProductIdList.Add(Convert.ToInt32(rd["productId"]));
}
}
//pc
else if (userType == 3)
{
SqlDataReader rd = oDal.ProductsGetAllByDescLengthPcReader(country);
while (rd.Read())
{
ProductIdList.Add(Convert.ToInt32(rd["productId"]));
}
}
//retail
else
{
SqlDataReader rd = oDal.ProductsGetAllByDescLengthRetailReader(country);
while (rd.Read())
{
ProductIdList.Add(Convert.ToInt32(rd["productId"]));
}
}
oDal.Dispose();
}
//make sure we don't have an empty array
if (Quantities.Count > 0)
{
quantity = Quantities[index];
}
else
{
quantity = 1;
}
int productId = ProductIdList[index];
AddItemsToCart(productId, quantity, hasAutoship);
}
Я испробовал множество различных исправлений, включая передачу значения NULL в мой источник данных, изменение состояния просмотра и перемещение это внутри! isPostback (кнопка ссылки не будет работать). Каждый раз, когда вы нажимаете кнопку ссылки, она перезагружает страницу (не go в! IsPostback), и обновление страницы имеет тот же эффект. Каждый раз, когда страница обновляется, она добавляет в корзину еще один последний выбранный товар. Я перепробовал все, что мог придумать, и все, что нашел в Интернете за последние несколько часов.
Буду признателен за любые предложения!