I am building a small website with some books to sell and need to implement a simple solution to add books to a basket (maybe a Session["buylist"]) and allow the user to place an order with an eMail.
In one page i have a gridView filled with a dataReader from the SQL Database and was able to add one columne to the left with one image that calls a method in c# that takes the line/columne ISBN and adds it to the Session["buylist"].
So far so good.
In another page i have a small block with html divs and one image as buy button but the "onClick" event only works with Javascript. I tryed to call javascript with the ISBN variable and show some alert messages. I can add Session["variable"] to a "var temporary" variable inside javascript but i cannot assign the result back to the C# Session["buyList"]
And in HTML i cannot call my c# method from an image directly with "onClick event".
<script type="text/javascript">
function fonction_ajouterPanier(ISBN) {
window.alert('<%= Session["PanierCommande"] %>');
var temp = '<%= Session["PanierCommande"] %>';
temp += (" " + GenCod);
window.alert(ISBN);
'<%= Session["PanierCommande"] %>' = temp;
}
</script>
Is there an easiest way to create a list of items (integers) that stays across session pages that i can easilly reuse?
EDIT:
I tried with WebMethod but the code inside the javascript doesn't appear to be recognized:
[WebMethod]
protected void Fonction_ajouterPanier(string a)
{
Session["PanierCommande"] += a;
Response.Write(Session["PanierCommande"]);
}
<script type="text/javascript">
function fonction_ajouterPanier(GenCod) {
window.alert('<%= Session["PanierCommande"] %>');
var temp = '<%= Session["PanierCommande"] %>';
temp += (" " + GenCod);
window.alert(temp);
PageMethods.CSHARP_FunctionName(temp);
}
</script>