FormBlock Server Control in Ektron

2019-06-26 18:20发布

I am working in Ektron 8.6.

I have a FormBlock Server Control in my Template Page,It is having a DefualutFormID of a valid HTML form from workarea.The form in the workarea have got few form fields and their corresponding values.

While the template page is rendering I need to GET those form field values and re-set them with some other values.

In which Page –Cycle event I should do this coding?

I tried this code in Pre-Render Event,but I am unable to GET the value there,but I am able to set a value.

I tried SaveStateComplete event as well,no luck.

String s=FormBlock1.Fields["FirstName"].Value;

If(s=”some text”)

{

// Re-set as some other vale.

FormBlock1.Fields["FirstName"].Value=”Some other value”;

}

In which event I can write this piece of code?

标签: ektron
1条回答
祖国的老花朵
2楼-- · 2019-06-26 18:45

Page_Load works fine for changing the value of a form field. The default behavior is for the Ektron server controls to load their data during Page_Init.

The real problem is how to get the default value. I tried every possible way I could find to get at the data defining an Ektron form (more specifically, a field's default value), and here's what I came up with. I'll admit, this is a bit of a hack, but it works.

var xml = XElement.Parse("<ekForm>" + cmsFormBlock.EkItem.Html + "</ekForm>");
var inputField = xml.Descendants("input").FirstOrDefault(i => i.Attribute("id").Value == "SampleTextField");
string defaultValue = inputField.Attribute("value").Value;
if (defaultValue == "The default value for this field is 42")
{
    // do stuff here...
}

My FormBlock server control is defined on the ASPX side, nothing fancy:

<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>

And, of course, XElement requires the following using statement:

using System.Xml.Linq;

So basically, I wrap the HTML with a single root element so that it becomes valid XML. Ektron is pretty good about requiring content to be XHTML, so this should work. Naturally, this should be tested on a more complicated form before using this in production. I'd also recommend a healthy dose of defensive programming -- null checks, try/catch, etc.

Once it is parsed as XML, you can get the value property of the form field by getting the value attribute. For my sample form that I set up, the following was part of the form's HTML (EkItem.Html):

<input type="text" value="The default value for this field is 42" class="design_textfield" size="24" title="Sample Text Field" ektdesignns_name="SampleTextField" ektdesignns_caption="Sample Text Field" id="SampleTextField" ektdesignns_nodetype="element" name="SampleTextField" />
查看更多
登录 后发表回答