日期:2014-05-18  浏览次数:20422 次

如何让自定义控件标签之间的内容有效?
举例说:我自定义一个文字输入的控件
后台代码
//mylabel.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;


namespace mylabel
{
  public class mylabel:Control
  {
  public string text = "";

  public string Text {
  get 
  {
  return text;
  }
  set
  {
  text = value;
  }
  }

  protected override void Render(HtmlTextWriter output) {
  output.RenderBeginTag(HtmlTextWriterTag.A);
  output.Write(text);
  output.RenderEndTag();
  }

  }
}

前台代码
//default.asp
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="mylabel" Namespace="mylabel" TagPrefix="mm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <mm:mylabel Text="mylabel" runat="server"></mm:mylabel>
  </div>
  </form>
</body>
</html>


那么在网页上的输出为mylabel
但是我现在不想通过设置Text的值,而是将要输出的值放在两个标签之间如:
<mm:mylabel runat="server">mylabel</mm:mylabel>
来将“mylabel”输出,需要在自定义控件的时候再怎么设置?

求牛人的回复
急等

------解决方案--------------------
cs 
public string mylable="123";

aspx

<mm:mylabel runat="server"><%=mylable%></mm:mylabel> 

这个意思?


------解决方案--------------------
放文本和放控件是两回事吧