views:

656

answers:

3

Hi,

I have a javascript code which builds a link with 2 params.

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

I've tried using cookies for posting the params, but somehow I can't read them on the server side.

this is the client side code

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

this is the server side reading code

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

Can you hep me out?

+1  A: 

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

To post data to any page, you HAVE TO use the path to that page. As for your problem with setting the cookies, they can only be used by a page in the same domain.

Kirtan
I'll be more specific: I don't want to post the data, i wat to create a link to anasp.net page and when it hit the data from the client will be sent by post
oz radiano
A: 

Are you doing an HTTP Post? You could post these values inside a form field. I'd use a hidden input field. You can add one in your markup or add one via the javascript.

Your other option is to use some sort of Ajax and pass JSON or XML in the body of the post.

Cookies are meant to save data client side accross pages and/or sessions.

JoshBerke
+1  A: 

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

Then when user clicks the button or the link the function will replace the value of those parameter something like:

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

To get the parameters back into code use Request.form("parameter1") and so on...

backslash17
What if the js code is in another file? he cannot identify the form.
oz radiano
Then you pass the form into the function through a parameter.
Min
Thanks, I've tried it, but now i cannot access the form's parameters on the server side. this is my new code:client side:<form name="myForm" id="myForm" action="/Users/AddUser/JoinUs.aspx"> <input type="hidden" id="name"/> </form>document.getElementById("name").value="value"; server side:string[] lat = Request.Form.AllKeys;and I get nothing!Thanks in advance.
oz radiano
The hidden input field requieres a name attribute, because the id is not enough to pass it by post<br><input type name="yourfieldnamehere" id="name">Then at server use <br>string[] lat = Request.form("name") //Nothing more nothing else
backslash17
Sorry remove the <br> from the previous comment...
backslash17