Why <% %> instead of events ?

G

Guest

Hey
Why in all books authors are using <% DataBinder.Eval(...) %> instead of
events of datagrid for example ? There is such event like Item_DataBound but
MOST books forget about this... I believe using event will give us a full
code behind instead of ... code-behind with binding inside. Can anyone tell
me why most programmers ( including myself ) is using <% %> instead of
events. And why it's so well hidden that we can use Item_DataBound ( many
books forget to tell us there is even such a event , and usually NO EXAMPLE
on using it ). Perfomance reasons ? Code is cleaner ? Events usually needs a
few more lines... but it makes code cleaner so it's probably worth it ?
Jarod
 
A

Andy Fish

Jarod said:
Hey
Why in all books authors are using <% DataBinder.Eval(...) %> instead of
events of datagrid for example ? There is such event like Item_DataBound
but
MOST books forget about this... I believe using event will give us a full
code behind instead of ... code-behind with binding inside. Can anyone
tell
me why most programmers ( including myself ) is using <% %> instead of
events. And why it's so well hidden that we can use Item_DataBound ( many
books forget to tell us there is even such a event , and usually NO
EXAMPLE
on using it ). Perfomance reasons ? Code is cleaner ? Events usually needs
a
few more lines... but it makes code cleaner so it's probably worth it ?
Jarod

There are many different ways to build up a control tree and render it in
asp.net. I would say it's just a case of using whatever works best in a
particular circumstance. In my asp.net application we use both the
approaches you describe.

on one hand, the code is cleaner if you put it in the code behind file (I
try to steer clear of using any programming constructs in <%# %>). on the
other hand, the aspx file is supposed to contain the presentation.
 
G

Guest

on one hand, the code is cleaner if you put it in the code behind file (I
try to steer clear of using any programming constructs in <%# %>). on the
other hand, the aspx file is supposed to contain the presentation.

Let's assume we don't anything about design... we are just programmers we
have to build an application. We put our controls on the page, and now we can
give this aspx file to the designer or after we end up programming. So
designer won't damage your job, by deleting some databinding stuff. And what
I forgot to tell DEBUGGING ! There is nothing to debug in aspx because the
debugger help is very poor ( if any ? ), but in event you can debug almost
every aspect of databinding.
Jarod
 
G

Guest

Both approaches are useful.

Normally, <%# %> can be used to handle simple situation, and ItemDataBound
event can be use to deal with complicated situation such as re-process data,
conditional showing data, and so on.

HTH

Elton Wang
(e-mail address removed)
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top