【发布时间】:2013-06-06 20:40:44
【问题描述】:
我正在尝试在 Umbraco 6.0.6 编辑器中使用 .NET 用户控件宏,但使用 formview 控件我无法在 page_load 事件中访问其中的控件。
例如:
ASCX:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="teste.ascx.vb" Inherits="usercontrols_teste" %>
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert">
<InsertItemTemplate>
<asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
</InsertItemTemplate>
</asp:FormView>
代码文件:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
FormView1.DefaultMode = FormViewMode.Insert
CType(FormView1.FindControl("txt_name"), TextBox).Text = "name"
End Sub
母版页模板:
<form id="form1" runat="server">
<umbraco:Item ID="Item1" field="conteudoPagina" runat="server"></umbraco:Item>
</form>
结果是“对象引用未设置为对象的实例”。在线上: CType(FormView1.FindControl("txt_name"), TextBox).Text = "name"
这仅在从 umbraco 编辑器呈现控件时发生,如果我在网页或母版页中正常使用该控件,它可以正常工作。
有相同结果的人吗?
谢谢
【问题讨论】:
-
抱歉,我刚刚注意到这个问题是在一个多星期前提出的。希望我的回答仍然有帮助!我真的建议在您的项目中包含 FindControlRecursive 辅助方法。我一直在使用它。
标签: asp.net .net vb.net umbraco webforms