Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Regular Expression View modes: 
User avatar
Member
Member
sean.kinley-techfringe - 3/22/2010 2:05:53 PM
   
Regular Expression
I've created a custom web part for data entry. I'm also using the Properties section of Development>WebParts by creating a number of Atriibutes for the web part. So far, I've used this for constraining character maximums and label/textbox widths.

Now, I'd like to apply Regular Expressions to the textboxes to constrain data entry. This works perfectly within the CMS Desk when configuring the web part, but how can I access this attibute value from within .NET using C#? In other words, I'd like to present a web user (not CMS Desk user) with a similar alert regarding the Regular Expressions constraints. Is there a method I can use for this? I did check the developer's guide and found that doesn't appear to be anything regarding this.

I can always create the code myself within C#, but I thought there must be an easier way since the constraints can be added to the web part attributes.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/25/2010 9:27:18 AM
   
RE:Regular Expression
Hello,

I am not sure what your web part do. However, I suppose you have for example a text box inside the web part which you want to validate. We check the fields in BizForms by default. BizForm documentation is here: http://devnet.kentico.com/docs/devguide/bizforms_module_overview.htm.

Then you may consider standard ASP.NET validators. You may find more information here for example: http://msdn.microsoft.com/en-us/library/aa479013.aspx
http://devhood.com/tutorials/tutorial_details.aspx?tutorial_id=46


Best regards,
Helena Grulichova

User avatar
Member
Member
sean.kinley-techfringe - 3/26/2010 9:55:52 AM
   
RE:Regular Expression
Thank you for your response. As you suggest, I will just code it myself in .NET.

But, so to clarify what I was asking...

Let's say I have a web part WebPartA which contains a label lblField1 and a textbox txtField1

In CMSManager > Development > WebParts > MyWebParts > WebPartA > Properties
I've created an attribute called lblField1 to control the label name. For example, I call to this using:

lblField1.Text = (string)PartInstance.GetValue("lblField1");

I also created an attribute called txtField1 and was assigned a regular expression contstraint to it. But, it looks like this only applies to when I use the confiruation pop up in CMSDesk > Design for that web part. I was hoping I could also call to it using .NET...something like...

txtField1.ValidationExpression = (string)PartInstance.GetValue("txtField1.RegularExpession");

but I don't know if there's a method for this.

I can, of course, just create my own attribute to handle this part to, but it seems redundant if you already have the field value there. It might make more sense to do it as it's own attribute text value any, since I don't think there's a way to edit the regular expression using CMSDesk > Design > Web Part Config.

Anyway, not a big deal, I've already coded it manually.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/29/2010 6:22:13 AM
   
RE:Regular Expression
Hello,

thank you for your explanation.

Regrettably, there is not any easy way how to access that value. It is stored in the database in XML format in CMS_WebPart table. You would need to access the database and split the string. Alternatively, it should be accessible by PortalEngine.WebPartInstance.Properties which returns the hashtable.

However, I would recommend you validating by ASP.NET code which you use now.


Best regards,
Helena Grulichova