【发布时间】:2009-02-24 19:23:47
【问题描述】:
我正在使用 ASP.Net Web 应用程序项目。我有一个用户控件,其中有一个 asp.net 按钮。当我在页面上使用该用户控件时,按钮不会出现,但如果我将按钮直接放在页面上,则会显示按钮。知道问题是什么吗?
此外,在该用户控件中,我可以覆盖渲染方法,并且传递给渲染方法的测试有效,但我仍然没有得到按钮
程序集在 web.config 中注册
编辑:在 dave 的帖子之后,我发现 .ascx 文件中的任何内容都不起作用,而覆盖该用户控件的渲染方法起作用
页面
<%@ Page Title="Home" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Site.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<uc:SomeCustomControl ID="myControl" runat="server" />
<asp:Button runat="server" Text="outControl" />
</div>
</asp:Content>
控制 .ascx 文件
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="Site.Controls.TestControl" %>
<asp:Button runat="server" Text="InControl" /><!--cant see this button-->
<p>I can't see this</p><!--cant see this text-->
.ascx 文件的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Site.Controls
{
public partial class TestControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("I can see this");
base.Render(writer);
}
}
}
以及页面来源
I can see this
<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="outControl" id="ctl00_ContentPlaceHolder1_Button1" />
【问题讨论】:
-
你能发布一些示例代码吗?
-
编辑您的问题并在您添加自定义控件的地方添加一些代码,然后我们可以为您提供帮助。
-
既然你在渲染中得到了东西,我会假设这只是一个“示例错误”,但你没有在页面代码中引用你的控件。
-
我在 web config 中注册了程序集
标签: asp.net