Say i have a TextBox control inside of a ListView where the text is DataBound and I want to use TrimStart. What is the proper way to define the char parameters? When I enter an apostrophe I get a server tag not well formed error… Example below:
<asp:ListView> <!--here-->
<asp:TextBox runat="server" Text='<%# Eval("Value").ToString().TrimStart('.',':') %>' />
</asp:ListView>
This is a simplified example of what I am really doing. In my situation I must do this trim in the aspx page.
Take your code out of you page and implement
OnDataBindingfor theTextBox. I wish more people would do this as it keeps the markup a lot cleaner and puts the code in the codebehind.Example:
Then implement it in your code where you don’t have to deal with these issues and it will get your ‘code’ out of the markup:
I personally try to put no inline code in my markup when possible if using ASP.NET WebForms.
OnDataBindingis one of the least explicitly used events and in my opinion helps to create clean markup and keep all your ‘code’ in the codebehind.