Mohit Kumar
Mohit Kumar

Reputation: 2069

Pass client side value to server side

I need to use a javascript variable value in server side.

Example:

JavaScript

var result =  false;

CS Code

if(result)
{
     Console.Write("Welcome..")
}
else
{
     Console.Write("plz try again..")
}

Note

I don't want to post a hidden field.

Upvotes: 0

Views: 246

Answers (2)

Quentin
Quentin

Reputation: 944320

With each request, any server side code will run and then any client side code will run. You can't switch between them at will.

Your options are:

  1. Provide all the data to the client in the first place, then use JS to decide which of them to keep/delete/show/hide/etc
  2. Use Ajax to make a second request to the server with the data you get from JS, return content, and then do something with that content in the JS callback function.
  3. Make a second request to the server and load a complete new page.

Remember to build on things that work.

Upvotes: 2

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

best way to do this use hidden fields...

Upvotes: 0

Related Questions