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
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With