2011-11-17 2 views
1

데이터베이스에 저장된 html 페이지를로드하라는 제안이 있습니까?ASP.NET 페이지의 데이터베이스에서 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

제안 사항이 있으십니까?

더 좋은 방법이 있습니까?

감사합니다.

Request.Form["txtSomething"] 

당신이 얻을 수 있다는 것을 의미합니다 : 당신이 당신의 양식을 읽을 필요 해요 손으로 컨트롤 모음 (까다로운 사업)에 컨트롤을 추가하지 않는 한

+0

그건 html 페이지입니다.시작 부분에 Aspx 마크 업이 없으므로 코드 배후에서 파생되었음을 나타내며 페이지가 컴파일되었음을 나타내지는 않습니다. 따라서 코드 뒤에서 결코 나타나지 않을 것입니다. HTML이 완성 되었습니까? –

+2

데이터베이스에서 원시 html을 렌더링하려는 경우 핸들러 (ashx) 파일과 Response.Write()를 사용하여 HTML을 출력합니다. –

+0

VirtualPathProvider 살펴보기 http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx –

답변

2

간단히 대답하면이 기능을 사용할 수 있습니다. 우리는 이와 비슷한 방식으로 모든 고객 별 맞춤 설정을 제공합니다.

긴 대답은 응용 프로그램과 HTML을 약간 재구성해야한다는 것입니다.

가장 쉬운 방법은 UserControls를 사용하는 것입니다. 기본적인 방법은 다음과 같습니다

1), 당신은 DB에서 추출 할 때, 즉 UserControl이 같은 DB에 저장되어있는 페이지 콘텐츠,

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

2) 만들기 디스크에있는 파일에 저장 ascx 확장자 (지금은 content.ascx라고 함). 페이지 초기화에서)

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

4 사업부로 컨트롤을로드하고 초기화 :

3) ASCX가에로드 할 서버에서 실행 사업부를 추가 할 메인 페이지를 수정 :

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 컨트롤에 포함 된 컨트롤 모음에 액세스하십시오.

페이지 다시 게시에서 표준 페이지 수명주기 때문에 페이지로드 이벤트가 발생할 때까지 컨트롤에 내용이로드되지 않습니다.

코드 비하인드가 필요하지 않으며 위의 설명대로 정확하게 작동하는지 확인했습니다.

+0

이렇게 할 것입니다. 나중에 나는 결과를 게시합니다. 감사!! – Gus

1

는 옛날 방식으로 값 이름을 알고 있으면 컨트롤에 포함 된 문자열 값이지만 그다지 많지 않습니다.