client-side vs server-side

G

Guest

hey all,

i'm having trouble understanding the connection (if there is one beween)
client-side scripting and server side scripting. For example can a variable
that is defined in the code-behind be accessed by client-side code, vice
versa? Any other tips related to the subject is welcomed as well.

thanks,
rodchar
 
D

darrel

i'm having trouble understanding the connection (if there is one beween)
client-side scripting and server side scripting.

There really isn't a connection.
For example can a variable
that is defined in the code-behind be accessed by client-side code

The server side code can write something to to the page that the javascript
can then read. HTML has to be the 'middle man' for that, though. You can't
directly read a server-side variable from javascript on the client side.
vice
versa?

Vice Versa is harder, since javascript can't actually change the markup that
the server sees. You can have the javascript postback with a querystring, or
have javascript write to a form field, and then grab the form field value on
postback.

Just remember that there is a rendered page in the middle.

javascript <--> CLIENT COMPUTER <--> rendered html page <-->SERVER <-->
Codebehind

-Darrel
 
D

darrel

The server side code can write something to to the page that the javascript
can then read. HTML has to be the 'middle man' for that, though. You can't
directly read a server-side variable from javascript on the client side.

More specifically, the server side code could actually write the javascript:

function sampleJavascriptFunction(This){
var el = <%=yourDotNetVariable%>;
}

-Darrel
 
J

Jeremy Chapman

Normally no, but you could create an http request in javascript, receive the
request server side with c#, pass back some data then interpret it with
javascript. Look up ajax if you are interested in this. It is a way to
call server side code from javascript.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top