Blog Posts List

System.InvalidOperationException – Eval(), XPath(), or Bind()

by Yugolancer

Posted on February 04, 2016



If you get the following error you are about to get the solution either :)

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Cause:

Usually it happens when you directly call say an Eval() function in the code-behind.

For example, you may have a GridView control with a label inside of the Template column:

<asp: id=" lblDescription " runat=" server " text="< %# Eval('Description') % >"></asp:>

 

Then for some reason you decide to move that to the code-behind AS IS so you say:


Dim lblDescription As Label = CType(e.Item.FindControl("lblDescription"), Label)
lblDescription.Text = Eval("Description").ToString()

Your project will compile but as soon as you try to open the certain Page, an exception ‘System.InvalidOperationException’ will be thrown.

Solution:

Just replace Eval() with DataBinder.Eval() making your code to looks like this:


Dim lblDescription As Label = CType(e.Item.FindControl("lblDescription"), Label)
lblDescription.Text = DataBinder.Eval(dataItem.DataItem, "Description").ToString()

Voila! Your problem has been solved.

Read More


Code Debugging - Is it easy?

by

Posted on February 22, 2018



As mentioned many times by now, Debugging is a discipline that requires patience, and a fervent attention to detail.

When it comes to solving difficult problems, issues or bugs, you need to locate, and resolve the problem's root cause.

Usually it happens that, after going through one idea after another and hitting debug button for an hour (usually more like 2 or 3 hours), you are not closer to solving the problem than you were when you started.

Now, all you've done is wasted a few hours of time, and worked yourself into a desperate and frustrated state that is not conducive to thinking rationally, and applying logic.

Simply because you don't actually have any clue what's causing the problem you are just shooting blindly.

The problem is often, if not always, more complicated than we would like.

As developers, we would much rather add new features, or write the next great algorithm, than try to figure out why something we wrote a month ago is suddenly no longer working.

"Stop thinking, and look!" - is one of the maxims from David Agan who points out that the engineers like to think and not to look.

Why? Well because the thinking is fun. In fact, for a lot of us it's probably why we became software engineers in the first place.

So why do we insist on being able to locate a bug by thinking about it? Probably because it's a lot easier than looking for it.

Of course, looking is tedious. Sometimes you don't even know where to start looking.

However, in order to be certain that you're fixing the right problems, and that you can prove that you've fixed it, make sure that every time you debug a problem you:

  1. Observe the issue in action
  2. Apply your fix
  3. Observe that the issue is resolved

If you don’t do these steps, in that order you can’t know if you actually solved the issue at hand, another different issue, or just wrote a bunch of code that does nothing at all.

So avoid frustration, don't waste time solving the wrong things, and stop thinking, and look already!

Read More


A regex that matches all credit cards

by

Posted on January 26, 2011



This is a regular expression that validates all credit card numbers including VISA, MASTER, AMEX and DISCOVERY! ^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$

 

< asp:regularexpressionvalidator id="CreditCardValidator" runat="server" controltovalidate="CreditCardNumber" display="Static" errormessage="Please enter valid card number" validationexpression="^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$" validationgroup="CustomSignup" text="*" />


Read More


Page 1 of 1

Copyright © ASPNETer 2006 - 2016