将Web用户控件拖放到设计图面上时,它将自动分配tagprefix = uc1。如何更改用户控件中的默认tagprefix
是否有人知道如何更改所有网页用户控件的默认tagprefix 您拖到Web表单上?
将Web用户控件拖放到设计图面上时,它将自动分配tagprefix = uc1。如何更改用户控件中的默认tagprefix
是否有人知道如何更改所有网页用户控件的默认tagprefix 您拖到Web表单上?
Adding User Controls to a Web Forms Page
你必须Register
的Page directive
像下面低于控制。
<%@ Register TagPrefix="Guest" TagName="GuestExample" Src="~/YourControl.ascx" %>
,然后更改TagPrefix
和TagName
按您的要求。
例
<Guest:GuestExample ID="ID" runat="server" />
,而不是复制他们的所有网页,只需申报一次即可 新pages-内>控制与连接段.config文件的 您的应用程序:
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="Guest" src="~/YourControl.ascx" tagName="GuestExample"/>
</controls>
</pages>
</system.web>
</configuration>
此方法也可以工作,但这不是我想要的..我想要拖出用户控件时,它会自动分配我分配的tagprefix – user1328360 2012-04-18 03:43:21
为了设置'UserControl'的TagPrefix和TagName。首先需要注册控件。 '拖放'WebUserControl'会将其转换为'Anchor'标签。 – Pankaj 2012-04-18 05:14:37
该方法是手动更改的 – user1328360 2012-04-18 07:09:19
实际上,这可以使用Assembly-Level属性TagPrefix来实现。
<Assembly: TagPrefix("MyCompany.Web", "SomeFancyTagPrefix")>
Public Class MyCustomControl
Inherits WebControl
'class implementation
End Class
第一个参数是控件的命名空间,第二个参数是您喜欢的标签前缀。
拖放您的自定义控制到页面上时,其结果是:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="MyCompany.Web.WebForm1" %>
<%@ Register Assembly="My Company" Namespace="MyCompany.Web" TagPrefix="SomeFancyTagPrefix" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<SomeFancyTagPrefix:MyCustomControl ID="MyCustomControl1" runat="server">
</SomeFancyTagPrefix:MyCustomControl>
</div>
</form>
</body>
</html>
你的意思的选择吗? – user1328360 2012-04-18 01:56:20