Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Adding Watermark to textbox in custom control via code View modes: 
User avatar
Member
Member
matt-awg - 9/19/2013 3:05:32 PM
   
Adding Watermark to textbox in custom control via code
I have made a custom form control based on the country selector that includes a zip code which appears and/or is required depending on what country is selected. I added it to the control like so:

<cms:CMSTextBox ID="zipCodeTextBox" runat="server"  />

Then in the OnPreRender I try to set the class of the control and also add the watermark like so:

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

//other code left out that determines if zip should be required here

zipCodeTextBox.WatermarkText = "test";
zipCodeTextBox.CssClass = "required TextBoxField";

The class gets set successfully as the country drop down is changed (I can see the style of the input change) and no errors occur, but no watermark appears either when zip code is required. Am I missing something? Is this not the write place to put the code (onPreRender)? Is something more required to make watermark work? Or can it just not be set in code like this?
Thanks,
Matt

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 9/20/2013 7:29:36 AM
   
RE:Adding Watermark to textbox in custom control via code
From what I see it looks correct (assignment, declaration, etc) so it must be timing. Try overriding the page load event. If you check the actual CMSTextbox, the properties are assigned in PreRender so depending on where the control is in the stack it might get rendered without those properties set or set too late.