开发者

Shopping cart Asp.net

开发者 https://www.devze.com 2023-03-10 12:56 出处:网络
I have a aspx page and inside I have called a .ascx page which is the shopping cart , on the aspx page I have a lot of links to the books and we can add the books to the shopping cart. On clicking the

I have a aspx page and inside I have called a .ascx page which is the shopping cart , on the aspx page I have a lot of links to the books and we can add the books to the shopping cart. On clicking the add button i store the bookid,name,price in a cookie and on the ascx page i get the copy and paste the value in the shopping cart using session variable everything is working fine..The code is something like this..on clicking the add btn i call this javascript function

       function addCookies(typeShopping,id,name,price) {

       document.cookie = typeShopping + "=" + id + "," + name + "," + price;
       }

But after this I have to do post back so the ascx page loads and adds this info to the shopping ca开发者_开发百科rt. so on the btn which call this function is like this..

      <a onclick="addCookies('ShoppingCart',1, 'A summary of the Creed....' ,25);"href=".../ShowBooks.aspx?CategoryName=Qur'an&Mushaf&CatID=1" </a>

but this as you see cause the page to post back and although the item adds to the shopping cart I move to the top, how can I do that I just click and the item add and the page don't post back and I stay on the same book.


You need to return false; from the onclick handler to prevent the browser from following the default action.


You'll need to tell the addCookies method to return false; after performing the necessary operations. This will stop the link from actioning.

function addCookies(typeShopping,id,name,price) {
       document.cookie = typeShopping + "=" + id + "," + name + "," + price;
       return false;
       }
0

精彩评论

暂无评论...
验证码 换一张
取 消