I have a repeater control with some html controls being populated from some server side DataSource. The code for these controls inside the repeater looks something like this..
<img src='<%# DataBinder.Eval(Container.DataItem, 'Path')%>' title='<%# DataBinder.Eval(Container.DataItem, 'Name')%>' alt=''>
I needed to format some of the text so I added a method to this code. The method I added is a server side method though. So I’m assuming this isn’t exactly the best way to handle things in terms of performance. The code looked something like this…
<span><%# trimItemName((DataBinder.Eval(Container.DataItem, 'Name'))%></span>
trimItemName(Object obj) is a server side method that will obviously trim the name.
Is there a way I can do this using javascript so doing a simple string trimming (or any other kind of formatting) doesn’t have to be done on the server side?
You can always do:
But I’m not really sure how moving it to the client-side would buy you anything. You risk not getting it trimmed if the user has JS disabled or doesn’t support it (~10% of internet users), plus the development overhead of keeping your client-side and server-side logic in sync.