HTML and C#

N

Neil B

I'm new to C# and VS 2008 Web App development. I can't find anything that
explains how variables and other information is shared between the C#
(behind)code and the HTML in the same page. I understand the the
<%=variable%> is used in HTML but any variable that I define in the C# code
gives an error that its not in the context.

How does C# and HTML share variables????

Is there any good discussions on their relationship?

Thanks,
Neil
 
A

Alberto Poblacion

Neil B said:
I'm new to C# and VS 2008 Web App development. I can't find anything that
explains how variables and other information is shared between the C#
(behind)code and the HTML in the same page. I understand the the
<%=variable%> is used in HTML but any variable that I define in the C#
code
gives an error that its not in the context.

How does C# and HTML share variables????

Basically, they don't. C# is running on the server and html in the
client. The memory spaces are different and no variable can be shared.
When you need to share some information between the server and the
client, you have to move it back and forth between both machines. One way to
move information is the one you mentioned: Writing <%=variable%> in the
..aspx file will cause the server code to replace that text with the content
of the variable, which is then inserted into the html code which is in turn
sent to the browser. Therefore, the content of the variable will be "seen"
by the client code. Note: Mark the variabe as "public"; you will get an
error if it is "private".
 
I

Ignacio Machin ( .NET/ C# MVP )

I'm new to C# and VS 2008 Web App development. I can't find anything that
explains how variables and other information is shared between the C#
(behind)code and the HTML in the same page. I understand the the
<%=variable%> is used in  HTML but any variable that I define in the C# code
gives an error that its not in the context.  

post your code,
also remember that a var is by default private, if you want to be able
to use it in the aspx page you have to declare it as protected.
How does C# and HTML share variables????

Is there any good discussions on their relationship?
there is a aspnet NG
 
C

Cor Ligthert[MVP]

Neil,

As others all stated the code behind is running at the server, which is in
fact the IIS part (Internet Information Server).

As the ASPX page is rendered by that, then it changes the ASPX page in an
HTML page inserting JavaScript confirm the by you created DLL (in this case
with C#). The same happens when the page is send back (Don't think in C#
because that is only the program language that has created the DLL it can be
in the same case VB or/and any other program language that has the ability
to create a Net application)

Cor
 
N

Neil B

The problem was that you have to specifically mark each of the variables as
public (I didn't try protected). They don't inherit this property from the
partial class (which is public).

Thank for all your help.
Regards, Neil
 

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

Top