Ektron中的FormBlock服务器控件 [英] FormBlock Server Control in Ektron
问题描述
我正在使用Ektron 8.6.
I am working in Ektron 8.6.
我的模板页面中有一个FormBlock Server控件,它具有来自工作区的有效HTML表单的DefualutFormID.工作区中的表单很少有表单字段及其对应的值.
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.
我应该在哪个Page –Cycle事件中执行此编码?
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.
我也尝试了SaveStateComplete事件,没有运气.
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?
推荐答案
Page_Load可以很好地更改表单字段的值. Ektron服务器控件的默认行为是在Page_Init期间加载其数据.
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.
真正的问题是如何获取默认值.我尝试了各种可能的方法来获取定义Ektron表单的数据(更具体地讲,该字段的默认值),这就是我的想法.我承认,这有点hack,但是行得通.
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...
}
我的FormBlock服务器控件是在ASPX端定义的,没什么花哨的:
My FormBlock server control is defined on the ASPX side, nothing fancy:
<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>
当然,XElement需要以下using语句:
And, of course, XElement requires the following using statement:
using System.Xml.Linq;
因此,基本上,我用单个根元素包装HTML,以使其成为有效的XML. Ektron在要求内容为XHTML方面非常出色,因此该应该起作用.自然,应该在生产中使用它之前以更复杂的形式对其进行测试.我还建议您进行一些健康的防御性编程-空检查,try/catch等.
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.
一旦将其解析为XML,就可以通过获取value
属性来获取表单字段的value属性.对于我设置的示例表单,以下内容是表单HTML(EkItem.Html)的一部分:
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" />
这篇关于Ektron中的FormBlock服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!