开发者

Creating custom/intutive layout for controls

开发者 https://www.devze.com 2022-12-13 15:15 出处:网络
I have an address control which display the con开发者_C百科tact info of the person. so it displays something like

I have an address control which display the con开发者_C百科tact info of the person.

so it displays something like

1234, street City, CA 12345

Now i want to give user flexibility to create format out of it. For ex someone might want to display address as,

street, City, Country

OR

Just display their emails: s@s.com z@z.com

Any good ideas on how to it or similar examples? thanks


Give the user 6 fields to fill out (6 is an arbitrary number, could be more, could be less). Then have another field below where they can enter a format code, which your page parses and renders the result.

So the format code could look like this:

{f1}, {f3},{f5}-{f6}, @{f4} ({f2})

treat anything with curly brackets as a token representing a field, and treat everything else as a literal character. So if in the fields i was to enter something like this:

Field 1: Apartment 1B, Level 10, My Building Name
Field 2: 1234 Sesame Street
Field 3: Suburbville
Field 4: 
Field 5: Small Town 
Field 6: 90210

then using the above format code, the output would be:

Apartment 1B, Level 10, Suburbville,Small Town-90210, @ (1234 Sesame Street)

using a format code is both simple for the user to understand, and very simple to implement as all you need to do is substitute in the appropriate values in place of the tokens (much like how string.Format() works).

One last thing to check for: when allowing free-form text entry like this, make sure you process the result through an appropriate anti-XSS library before rendering it to the screen (Microsoft supply a very good and simple to use anti XSS assembly you can download for free and use).

0

精彩评论

暂无评论...
验证码 换一张
取 消