• RV
    • Missy – My Home
    • JBAM – Newmar Dutch Star
    • Shaneeda
    • Buying a Used RV
    • Gas vs Diesel RVs
    • Ideal Motorhome
    • Choosing the Ideal RV
  • Cycling
  • Jeep
  • About
  • Flying
    • Vans RV-4
    • Daisy – RV-3B
  • Resources
  • Subscribe

JdFinley.com

Fulltime RV Living Adventures

  • Is Solar For You?
  • Gas vs Diesel RVs
  • Buying a Used RV
  • Choosing the Ideal RV
  • Ideal Motorhome

Data Binding EVAL

December 16, 2011

I found a neat little trick this past week. Probably something that all other programmers that are using data binding already knows…

Microsoft ASP.Net FrameworkIn short, I needed to show JavaScript Confirm popup following the click event of a LinkButton contained in a GridView on an ASP.Net 4.0 framework web site page. If not familiar, a Confirm popup requires the user to select “OK” or “Cancel” to proceed. The text of this Confirm needed to include some data from an object and not just a hardcoded message. The GridView was data bound to a collection of objects.  In this case, I needed to get that object property value into the text shown on the Confirm.

The typical use of EVAL is to extract a property of the current, data bound object and return it as an object.  Typically, that object is a string and it is stuffed into or used by some control on the page (textbox, label, etc…).

The following is a fairly typical example of EVAL usage:

'<%# Eval("PropertyName") %>'

Assuming the value of the “PropertyName” property is “123”, the value return is “123”.

Thanks to overloads, another option is to format the property in a fashion much like a String.Format. Such as:

'<%# Eval("PropertyName", "The value is {0}") %>'

Which then returns “The value is 123” (Assuming the value of the “PropertyName” property is “123”).

This means that the second option can also be used to format the entire JavaScript Confirm statement, like this:

'<%# Eval("PropertyName","return confirm(""Item {1} is going to be deleted."")") %>'

When this is assigned to the OnClientClick event of an asp:LinkButton, the result is a client side, JavaScript popup confirmation asking the user “Item 123 is going to be deleted.”  When the user response is “OK”, the server-side code is called. If “Cancel”, the click event is canceled on the client-side avoiding a round trip to the server.

Nice!

Now, believe me, I understand how annoying these pop-up, confirmation messages are and also fully aware that they are ignored by most users. However; this was a requirement of the web site being developed so not something I dreamed up on my own to annoy users.  Hmmm…. now there’s an idea! 🙂

(Visited 113 times, 1 visits today)

Related posts:

Default ThumbnailObject Serialization (binary) Default ThumbnailIsolated Storage Default ThumbnailMore Object Serialization Default ThumbnailXML Serialization

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Everything will be all right in the end, if it’s not all right, it’s not the end.

— Unknown

Popular Posts

  • Powermatic Model 90 Wood Lathe & VFD
  • Wood Turning on a Lathe
  • Chainsaw Review: Sportsman 20 in. 52cc
  • Cielo Grande Barbed Wire Fence Repair

Email Notification


 

Posts by Subject

3DPrinting Aircraft Airstrip Bible Bus bus boys Camping Cat Computers Cycling Development Electrical electronics Entertainment Environment Factory Five family FAQ Finances flying Food God Health Holiday Home Humor kayak Life Maintenance Nature Photography Review RV-3 RV-4 sailboat sailing self improvement Sewing solar Travel Video weather wood woodworking X-Country

Posts by Month

© Copyright © 2025 JDFinley.com · All Rights Reserved · Privacy Policy

Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to JD Finley and JdFinley.com with appropriate and specific direction to the original content.