Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the difference between <%= and <%# ?

Status
Not open for further replies.

iamanson

Programmer
Aug 17, 2001
42
AU
Hi,
What is the difference between <%= and <%# ?
They confuse me so much [sadeyes]
 
<%#

Denotes the beginning of a databinding expression. ie:

Container.DataItem(&quot;fieldName&quot;)

and is executed at the time of databinding on either the page or the particular object where it's used. Will typically execute in a loop-type fashion for as many iterations as your datasource has rows. Whereas this:

<%=

is synonymous with:

Response.Write

and simply writes out some value to the response buffer that exists in memory -- one time only to wherever you put the statement.

:)
paul
penny1.gif
penny1.gif
 
ok. thx! :-D
My situation now is similar to that:
<script lang=javascript>
function compareTextBox() {
if (<%=box1.Value%> > <%=box2.value%>) {
alert(&quot;xxx&quot;);
}
}
</script>

Where box1 and box2 are two textbox in an editing datagrid.
<asp:datagrid id=&quot;grdData&quot; ....
<EditItemTemplate>
<asp:TextBox id=&quot;box1&quot;....
<asp:TextBox id=&quot;box2&quot;....
</asp:datagrid>

and I CANNOT use CompareValidator or server side code for the 2 values.
Should I use <%=box1.Value%> or what?
 
first: you cannot include asp tags in the javascript code.

second: you will not be able to access the box1 and box2 controls from javascript since the 2 controls are created during runtime. What you need to do is add some coding in the code behind.

you need to access the ItemCreated event of the datagrid and add an attribute to your update button that will control the values of the 2 textboxes

taka a look at this faq855-2019 Daren J. Lahey
Just another computer guy...
 
You can include asp tags in the javascript code. Works just fine, and from time to time, it's a very useful technique.

However, I do agree that you should go the code-behind route as Alcar has suggested. Best to lean on new stuff rather than use old hat tricks as a crutch.

:)
paul
penny1.gif
penny1.gif
 
=) you never know how long those tricks will continue to work...
I should have phrased it better: &quot;it isn't good practice to mix code in the HTML page&quot;.

hth Daren J. Lahey
Just another computer guy...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top