如何通过继承我的.cs页面中的内置控件来覆盖放在.aspx页面中的控件的属性。 [英] How to override the property of the controls placed in .aspx page by inheriting the built in controls in my .cs page.
问题描述
HI C #codes,
我有一个问题,如何通过继承我的.cs页面中的内置控件来覆盖放在.aspx页面中的控件的属性。
假设我考虑Label控件Text属性,
如果我在运行时拖放到任何.aspx页面应该显示文本这是标签,带有用户控制和自定义控制。
请帮助我,这将非常有帮助。
我试过这样做了。
我尝试了什么:
HI C# coders,
I am having one question, how to override the property of the controls placed in .aspx page by inheriting the built in controls in my .cs page.
Suppose if I consider the Label control Text property,
If I drag and drop to any of the .aspx page when I run that should show the text "This is label" with user control and custom control.
Please help me on this, this will be very much helpful.
I tried like this to achive.
What I have tried:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BatchImportExportApp.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form12" runat="server">
<div>
<asp:Label ID="labelBaseClass" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
ing System;
using System.Collections.Generic;
using System.Linq ;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
名称空间BatchImportExportApp
{
public partial class默认值:System.Web.UI.Page
{
protected virtual void Page_Load(object sender,EventArgs e){}
}
class labelBaseClass :标签
{
公共覆盖字符串文字
{
get
{
返回这是自定义标签。;
}
set
{
this.Text =这是自定义标签。;
}
}
}
}
ing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BatchImportExportApp
{
public partial class Default : System.Web.UI.Page
{
protected virtual void Page_Load(object sender, EventArgs e) { }
}
class labelBaseClass: Label
{
public override string Text
{
get
{
return "This is custom label.";
}
set
{
this.Text = "This is custom label.";
}
}
}
}
推荐答案
声音就像你正在寻找标签映射:
ASP.NET中的标签映射 - Mads Kristensen [ ^ ]
ASP.NET中的标记映射 - CodeProject [ ^ ]
这将允许您使用自己的自定义标签控件自动替换< asp:Label>
的每个实例。
Sounds like you're looking for tag mapping:
Tag mapping in ASP.NET - Mads Kristensen[^]
Tag Mapping in ASP.NET - CodeProject[^]
That will let you automatically replace every instance of<asp:Label>
with your own custom label control.
这篇关于如何通过继承我的.cs页面中的内置控件来覆盖放在.aspx页面中的控件的属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!