1

有什么建议可以加载保存在数据库中的 html 页面吗?

html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>xxx</title>

</head>
<body>
    <form id="Form1" runat="server" method="post">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />            
    </form>
</body>

代码隐藏:

 protected override void OnInit(EventArgs e)
    {
        this.IniciarFormulario();

        using (ServicoECMClient proxy = new ServicoECMClient())
        {
            tipoDocumento = proxy.ObterTipoDocumento(int.Parse(tipoDocumentoID));
        }

        if (tipoDocumento == null)
        {
            throw new ApplicationException();
        }

        this.Page.Header.InnerHtml = tipoDocumento.estilo; //css

        this.Page.Form.InnerHtml = tipoDocumento.form; // form 

        base.OnInit(e);
    }

我无法检索表单值。

看:

 foreach (System.Web.UI.Control controle in this.Form1.Controls)
            {
                if (controle.GetType().Name == "HtmlInputText" || controle.GetType().Name == "HtmlInputSelect"
                    || controle.GetType().Name == "HtmlInputRadio" || controle.GetType().Name == "HtmlInputTextCheckbox")
                {
                    if (!string.IsNullOrEmpty(this.Request[controle.ClientID]))
                    {
                        documento_indice documentoIndice = new documento_indice();
                        documentoIndice.id_indice = int.Parse(controle.ClientID.Split('_')[1]);
                        documentoIndice.valor = this.Request[controle.ClientID];
                        documentoIndice.timestamp = DateTime.Now;
                        documentos_indices.Add(documentoIndice);
                    }
                }
            }

控件为空。=> this.Form1.Controls

有什么建议吗?

还有其他更好的方法吗?

谢谢。

4

2 回答 2

2

简短的回答是,是的,您可以使用此功能。我们以与此类似的方式提供所有客户特定的定制。

长答案是它需要对您的应用程序和 HTML 进行一些重组。

我们发现实现这一点的最简单方法是通过 UserControls。基本方法是:

1)创建作为用户控件存储在数据库中的页面内容,即

<%@ Control Language="vb" AutoEventWireup="false" %>
<input id="txtTest" type="text" runat="server" />

2)当你从数据库中提取它时,将它存储在磁盘上的一个文件中,扩展名为 ascx(现在说 content.ascx)。

3) 修改您的主页以添加一个在将加载 ascx 的服务器上运行的 div:

<div id="divContent" runat="server">
</div>

4)在页面初始化中,将控件加载到div中并对其进行初始化:

Dim oControl As Control

' Load a user control
oControl = Me.LoadControl("content.ascx")
If oControl IsNot Nothing Then
    ' Ensure viewstate is enabled
    oControl.EnableViewState = True
    ' Set properties as required
    oControl.ID = "ContentControl"
    ' Clear the existing control(s) from the content container
    Me.divContent.Controls.Clear()
    ' And add the new one
    Me.divContent.Controls.Add(oControl)
End If

5) 访问包含在 div 控件中的控件集合。

请注意,在页面回发中,由于标准页面生命周期,在触发页面加载事件之前,控件不会将内容加载到其中。

我已经验证不需要代码隐藏,并且它的工作原理与上述完全一样。

于 2011-11-18T01:32:44.683 回答
1

除非您手动将控件添加到控件集合中(这是一项棘手的工作),否则您将需要以老式方式读取表单值:

Request.Form["txtSomething"]

这意味着如果您知道控件的名称,则可以获取控件中包含的字符串值,但仅此而已。

于 2011-11-18T00:53:17.930 回答