How to send parameters from javascript to asp.net?

I have javascript code that builds a link with two parameters.

Now I know how to post these parameters using an address, but I don't want to use it.

I've tried using cookies to publish parameters, but somehow I can't read them on the server side.

this is client side code

document.cookie="name="+"value";

      

this is the server side read code

string s = Response.Cookies[cookieName].Value;

      

Could you help me?

0


source to share


3 answers


Create a mini form (not just an asp.NET web form, just) with two hidden input type fields named as your parameters. After that, create a link or button to bind the onclick event to the javascript function (example: onclick = "javascript: postIt ();").

Then, when the user clicks on a button or link, the function will replace the value of that parameter with something like this:



document.miniform.parameter1.value = yourvalue1;
document.miniform.parameter1.value = yourvalue2;
document.miniform.submit();

      

To return parameters to code, use Request.form ("parameter1"), etc.

+1


source


You can use Ajax Request to post your data in an ASP.NET form.



To send data to any page, you must use the path to that page. As for your problem setting cookies, they can only be used on a page on the same domain.

+1


source


Are you making an HTTP post? You can post these values ​​inside the form field. I would use a hidden input field. You can add it to your markup or add one via javascript.

Another option is to use some kind of Ajax and pass JSON or XML in the body of the message.

Cookies are designed to store client-side data across different pages and / or sessions.

0


source







All Articles