Thursday, June 12, 2014

an interesting pitfall in wiring up a client side event for a DevExpress control in C#

MyButton.ClientSideEvents.Click = String.Format("function(s,e){{Whatever({0},
      {1},{2},{3});}}", foo, bar, baz, qux);

 
 

What is above will work great if foo, bar, baz, and qux are all integers, but if qux is a string you will get an error message in the console telling you that qux cannot be made heads or tail of. The better thing to do in that scenario is:

MyButton.ClientSideEvents.Click = String.Format("function(s,e){{Whatever({0},
      {1},{2},'{3}');}}", foo, bar, baz, qux);

No comments:

Post a Comment