Switching Context From HTML to Code Behind

G

Guest

Hey guys,

Apologies if this is in the wrong thread, whenever I search for <% or
"switching context" I get no results.

What I am trying to do is set the value of a html text box to a server side
value but I need to do it in the HTML and not the code behind. Has to do
with custom javascript events and what not.

In 1.1 I have this and it works fine:
<input id="myTextBox" name="myTextBox" type="text" value="myControl.Value" />

In 2.0 this doesn't work. The HTML editor seems to know what the <% and %>
are for as it highlights them but when I run the page and "View Source" i see
the following:
<input id="myTextbox" name="myTextBox" type="text" value="<%=myControl.Value
%>" />

So obviously it's not handling the tags properly.

Any ideas? This is driving me crazy!

Thanks
 
T

tdavisjr

Michael said:
Hey guys,

Apologies if this is in the wrong thread, whenever I search for <% or
"switching context" I get no results.

What I am trying to do is set the value of a html text box to a server side
value but I need to do it in the HTML and not the code behind. Has to do
with custom javascript events and what not.

In 1.1 I have this and it works fine:
<input id="myTextBox" name="myTextBox" type="text" value="myControl.Value" />

In 2.0 this doesn't work. The HTML editor seems to know what the <% and %>
are for as it highlights them but when I run the page and "View Source" i see
the following:
<input id="myTextbox" name="myTextBox" type="text" value="<%=myControl.Value
%>" />

So obviously it's not handling the tags properly.

Any ideas? This is driving me crazy!

Thanks

Try this:

<input id="myTextbox" type="text" value='<%= myControl.Value %>' />

Notice the single quote around the <%= %>
 
T

tdavisjr

Also make sure the value you are getting from the server is declared as
a Public or Protected Method or Property in your code behind class.

Make sure that you have the <%@ Page %> directive at the top of the
aspx page. This is all I can thing of.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top