How do I get code to fire on the HTML page instead of the code behind?

A

aaa

I fail to see the connection between the code behind and the raw HTML of
the ASPX page how do you get variables and functions to communicate with
each other?

I cannot get this to even fire:
<script Language=C# runat=Server>

public int myfunc()
{
int blah = 1;
if(blah != 0)
{

}
return 0;
}
myfunc();

</script>

I get the following error:
CS1520: Class, struct, or interface method must have a return type
 
B

Bruce Barker

in asp.net, functions and subs must be defined in in script blocks (<script
runat=server>), while inline code must in a <% %>

try:

<script Language=C# runat=Server>
public int myfunc()
{
int blah = 1;
if(blah != 0)
{

}
return 0;
}
</script>
<% myfunc(); %>


-- bruce (sqlwork.com)
 
A

aaa

Thanks, but again if I create a server side variable in my HTML how do I
reference it in my code-behind and vice versa?
 
V

Verde

<<if I create a server side variable >>
Answer #1: You can't. Server-side execution knows nothing about client-side
execution and vice versa. What you can do is store the value of a variable
in the page somewhere (e.g, TextBox or HTML Hidden field) on one side or the
other, then send the page (either down to the client or back to the server),
and then retrieve the value from whereever you put it in the page.

Answer#2: Your question makes no sense: "if I create a server side variable
in my HTML how do I reference it in my code-behind ". BY definition, a
server-side variable is in your code-behind. All code-behind executes on the
server; not on the client. Code that executes in the client is "client-side
script". So, [a server-side variable in my HTML], as you are thinking, is
something that doesn't exist. Put another way, HTML is just text, not a
"variable". HTML can hold a *value* of a variable (see Answer #1 above) -
and that value would be whatever value was current for the variable at the
time it was written to the HTML. A variable is not the same thing as its
current value; so "a server side variable in my HTML" doesn't make sense.

-HTH
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top