사용자 정의 컨트롤에서 HTML 렌더링 로직을 정리하고 싶습니다. 그런 다음 렌더링 할 때 사용할 수있는 UserControl에 사용자 지정 제품 개체 (제목, 축소판, ID 등)를 전달하려고합니다. 이상적으로는 이것을 리피터 (또는 for 루프)에서 사용하고 현재 맞춤 제품 오브젝트를 UC로 전달하려고합니다.리피터의 UserControl에 객체를 전달 하시겠습니까? .Net 1
내가 본 모든 예제는 UC 태그의 문자열을 통과했지만 실제로는 원하지 않는 방식으로 렌더링을해야하는 새로운 필드를 추가해야하는 모든 곳에서 참조가 필요합니다.
아이디어가 있으십니까?
<div>
<h3><%= myProd.title %></h3>
<img src="<%= myProd.thumbnail %>" />
<p>
<%= myProd.description %>
</p>
</div>
: VB.net (나의 첫번째 .NET에 대한 선택을 너무 쉽게 이동) 우리는, 이것이의 .ascx 페이지에있을 것입니다 가야하는
HTML 예제를 사용하여
닷넷 (1) 업데이트 :
그래, 여기 주변에서 해킹하는 것은 내가 생각해내는 것, 그게 작동하지 않는 것,이 퍼즐의 누락 된 조각은 뭐니?
은 UserControl을 생성하고 뒤에 코드에 이것을 추가 :Public Class ProductRender
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private _product As productItem
Public Property myProd() As productItem
Get
myProd = Me._product
End Get
Set(ByVal Value As productItem)
Me._product = Value
End Set
End Property
End Class
를 UC의 ASCX 페이지에서 단순히 위의 HTML을 가지고있다. 내가 그렇게으로 getDummyProduct를 선언 뒤에 코드에서
...usual ascx header stuff...
<%@ Register TagPrefix="ORC" TagName="productRender" Src="productRender.ascx" %>
<ORC:productRender id="Assetrender1" runat="server" asset="<%# getDummyProduct() %>" />
:
Public Function getDummyProduct() As productItem
getDummyProduct = New productItem("DVD Player", "It plays DVDs!", "some_thumb.jpg", 30)
End Function
아직 내의 ASC 페이지에서 내가 얻을 UC를 사용하는 페이지에서
나는 단순히 테스트를 위해 다음과 같은 추가 : "개체 참조가 개체의 인스턴스로 설정되지 않았습니다."Line 1: <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ProductRender.ascx.vb" Inherits="MyApp.ProductRender" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
Line 2: <h3>
Line 3: <%= myProd.title %>
Line 4: </h3>
".NET 1"은 무엇을 의미합니까? 1.0? 1.1? 오식? –
.Net 버전 1.1 VB.net –