0

I want to set one value in server side session in client side and need to access that session in web service, so i tried below

In client side :

//Set the server side session like below  
 var vr_="demo.png";     
'<%Session["path"] = "' + vr_ + '"; %>';

//In alert,checked the server side session value like below
 alert('<%=Session["path"] %>');

the value getting in alert is fine and i called the web service but when try to access the session in web service i am getting the following as session value

' + vr_ + ' not the original value "demo.png"

Please find the source code below,

In Javascript :

  var vr_="G:\\13-06-15-demo\\app1\\uploads\\demo.png"

In Jquery ajax request, i called the webservice like below

 $.ajax({
        url: "../webservice/email.asmx/senmail",
        data: "{'tomail': '" + tomail + "','subject': '" + subject + "','message': '" + message + "','attachment': '" + vr_+ "'}",           
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",

In web service, the method is like below

 public bool senmail(string toMailId, string subject, string message,string attachment)
    {
Nandha
  • 655
  • 1
  • 6
  • 14

1 Answers1

0

You've got a quotes problem, fix it like this:

<% Session["path"] = "'" + vr_ + "'"; %>

EDIT 1:
Javascript and ASP.NET are not the same, so you cannot access the variables, so you can't do it on the client side. You must send something to the server like a POST request using Javascript or easier using jQuery.

Here are some resources:

Using AJAX and Javascript:
http://www.w3schools.com/php/php_forms.asp http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

jQuery AJAX: http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.post/

EDIT 2:
The answer was to create a normal javascript object/array and then convert it to JSON using JSON.stringify(), like seen in this example: Jquery Ajax Posting json to webservice.

JSON.stringify(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Community
  • 1
  • 1
fsacer
  • 1,382
  • 1
  • 15
  • 23
  • No in that i am getting vr_ does not exist in current context – Nandha Jun 23 '15 at 05:37
  • Missed that javascript and ASP.NET are not the same, so you cannot access the variables, so you can't do it on the client side. You must send something to to the server like a post request using javascript or easier using jQuery. – fsacer Jun 23 '15 at 05:43
  • can u see the comment i given to @john saunders and help me – Nandha Jun 23 '15 at 05:45