Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Server side variable on client side and Vice versa Asp.Net and javascript

Tags:

asp.net

I have a requirement of adding server side variables in client side and other way round. Because I need to set a value from client side using javascript and access the same in code behind page.

I have to use C#.Net and javascript.

Any directions please

like image 387
Hari Gillala Avatar asked Dec 09 '10 09:12

Hari Gillala


People also ask

How can access JavaScript variable in ASP.NET code behind?

You cannot directly access the javascript variables in your code behind. You'd need to send the information to the server, for example by sending them back as form fields or query string parameters via an ajax request. jQuery is a great library to simplify the task of sending ajax requests, but many others exist, too.

Is ASP client side or server side?

Client Side Scripts All ASP.NET server controls allow calling client side code written using JavaScript or VBScript. Some ASP.NET server controls use client side scripting to provide response to the users without posting back to the server. For example, the validation controls.

Is ASP a server side technology?

ASP and ASP.NET are server side technologies. Both technologies enable computer code to be executed by an Internet server. When a browser requests an ASP or ASP.NET file, the ASP engine reads the file, executes any code in the file, and returns the result to the browser.

Can C# be used on client side?

It is a client-side solution based on HTML and CSS. C# is replacing the js part using web assembly. So nothing has changed on how you access/modify HTML controls. Also, JS and C# code can interact with Each other.


1 Answers

you can declare some variable at server side .cs file like public int myServerSideINT and can access it on .aspx file using

   <script type="text/javascript">
   function getServerSideVAR()
   {
        var serverVAR=<%= this.myServerSideINT %>;
   }
   </script>

i hope this will helpful to you

like image 122
BrainCoder Avatar answered Oct 03 '22 00:10

BrainCoder