0

我想为 Web 应用程序中的各种母版页创建一个通用标题用户控件。标头由大师共享,并具有徽标、导航和动态帐户按钮(例如我的帐户和注销)等常用项目。

我正在向表单添加动态链接按钮就好了,但是我想将它们移动到占位符位置。

问题是用户控件收到错误,当我将它添加到占位符时,“'LinkBut​​ton' 必须放在带有 runat=server 的表单标签内”。

uc_header.ascx.cs

LinkButton signout = new LinkButton();
signout.Text = "Sign-Out";
signout.ID = "SignOutLink";
signout.Click += new EventHandler(SignOutLink_Click);
//adding it to the form works but positions it at the bottom
this.Page.Form.Controls.Add(signout);
//I get an error when I try to add it to the placeholder 
SignOutHolder.Controls.Add(signout);

uc_header.ascx(例如简化)

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uc_header.ascx.cs" 
Inherits="Site.Masters.uc_header" %>

<asp:PlaceHolder ID="SignOutHolder" runat="server"></asp:PlaceHolder>

如何使用 .Net 将“退出”按钮添加或定位到占位符?

我的目标是创建一种注销所有页面并仅管理一个通用头文件的方法。

4

1 回答 1

1

听起来用户控件放置在表单之外。如错误消息所示,检查母版页并确保用户控件位于表单内。

于 2012-05-03T15:44:10.600 回答