-1

i am having a div and i am adding innerHtml in it using javascript. now what i want is that i have to set that innerHtml data in my session variable. and want to use that session variable in my another asp webform page. but i dont know how to perform this task.

here is the image link http://www.3ctechies.com/help.png where i have showed what to do acutally

any help will be highly appreciated.

i am doing it like this.

//cartDetailsDiv is a div in which i am adding innerHtml through javascript.

//now i am getting that innerHTML in my session variable like this

Session["_cartDetails"] = cartDetailsDiv.InnerHtml.ToString();

Response.Write(Session["_cartDetails"].ToString());

but i am getting nothing in my session variable.

please help me out.

Fazil Mir
  • 783
  • 2
  • 9
  • 23

2 Answers2

1

I wouldn't recommend using a session variable for this. It's kind of dirty.

The easiest way to do this is make an .aspx, lets say _cartdetails.aspx, that outputs this value, you can set the mime-type to either text or leave it as text/html. When you do a very basic ajax call to _cartdetails.aspx you can use the HTML data right away.

Marvin Brouwer
  • 306
  • 3
  • 13
  • i am having html button on which i am calling javascript function. so i cannot add OnClick Event on my html button. otherwise i would have done this. – Fazil Mir Oct 21 '13 at 10:06
  • I don't really understand this. If you are calling a javascript function you are able to do an ajax request. If you post some of your code it might be a lot easier to help you. – Marvin Brouwer Oct 21 '13 at 10:09
  • wait i will upload an image. so that you can understand. here is the link "http://www.3ctechies.com/help.png" – Fazil Mir Oct 21 '13 at 10:20
  • There are a lot of ways to do this with asp.net with or without JavaScript. Stack overflow allows you to put formatted code into your questions. If you use this people can see how your application works so they can help to answer your questions more specifically. – Marvin Brouwer Oct 21 '13 at 10:25
  • Adding Add To Cart Button In My Code Behind File. `protected void on_Load(object sender, EventArgs e) { string divDetails = "; cartDiv.innerHtml = divDetails; }` – Fazil Mir Oct 21 '13 at 10:32
  • Js Function `function addToCart(tax, del, name, id, qnty, price) { var exe = document.getElementById('showItems'); exe.innerHTML = exe.innerHTML + ""; }` – Fazil Mir Oct 21 '13 at 10:40
  • So if I understand correctly; when you're adding items to a cart you change the html which you do not upload or post to the server. At page load you build your own HTML with concatenating strings with a data object called dt1. I'd suggest you take a look at some tutorials about how asp.net webforms works, or maybe Ajax tutorials because this isn't really an efficient way to do this. – Marvin Brouwer Oct 23 '13 at 09:05
0
Session.Add("_cartDetails",cartDetailsDiv.InnerHtml.ToString());

It will works! :)

mashet
  • 836
  • 1
  • 10
  • 17
  • i did it another way. and this way doesn't work also. now wat i did i actually called two javascript functions. and i am passing all the data to the first function through parameter along with url of asp page. this function opens a pop up but it remains hide and all the data which is passed to the javascript function is assigned to session variable. and the second function is adding innerHtml temporary. :) – Fazil Mir Oct 24 '13 at 17:36
  • You wrote that you have 2 asp pages, so Session should work. I've never had situation that Session doesn't work with 2 asp pages. If you are interested, you can see how I did't in my case ;) http://stackoverflow.com/questions/19561877/is-it-possible-to-set-localstorage-or-session-variable-in-asp-net-page-and-read/19562951?noredirect=1#comment29030673_19562951 – mashet Oct 25 '13 at 09:56
  • no i am adding innerhtml through javascript in my div on asp page 1. now on click event i want that innerhtml should get stored in my session variable. but when i press click event, innerhtml returns null. – Fazil Mir Oct 25 '13 at 12:32