Friday, May 15, 2009

Well that’s weird – hidden validation controls

This is the first of a hopefully regular column. In it I’d like to cover weird bits of code that just don’t make sense and I haven’t seen elsewhere but are required to make something work. It is my hope that others can learn from my pain.

Today I’m going to cover server validation. Asp.net has a very handy custom validation control that can be used to check values preventing things like duplicates in a database. I won’t go into it as more information can be found here

http://www.4guysfromrolla.com/articles/073102-1.aspx

My issue came in that I have three groups of controls. Group one, two and a general group. The button you clicked determined if group one or two was validated but the rest where validated with a line of code like this.

Page.Validate("general");

This worked great until I decided that I should hide my form by default and show it only if needed.

panForm.Visible = false;

With the panel containing the control hidden when I called Validate(“general”) it preformed no validation. This is because although the control existed asp.net assumed it was not to be used as it was hidden. My eventual solution was to get the hidden state of the panel and unhide it then rehide it.

bool formVisibility = panForm.Visible;
panForm.Visible = true;
Page.Validate("general");
panForm.Visible = formVisibility;

One Problem solved, many more to come.

1 comment:

  1. In temporary, this is the technology that records every small detail in the gaming room and allows it to be streamed to players by way of a video link. Players are in a position to} place their bets by way of a console on their computer screen. If they need assistance, a stay chat operator is also be|can be} 1xbet korea available.

    ReplyDelete