Denotes the beginning of a databinding expression. ie:
Container.DataItem("fieldName"
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.
ok. thx! :-D
My situation now is similar to that:
<script lang=javascript>
function compareTextBox() {
if (<%=box1.Value%> > <%=box2.value%>) {
alert("xxx"
}
}
</script>
Where box1 and box2 are two textbox in an editing datagrid.
<asp:datagrid id="grdData" ....
<EditItemTemplate>
<asp:TextBox id="box1"....
<asp:TextBox id="box2"....
</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.
=) you never know how long those tricks will continue to work...
I should have phrased it better: "it isn't good practice to mix code in the HTML page".
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.