public class Editor : System.Web.UI.WebControls.WebControl
{
private string text;
       
public string Text
{
get
{
return this.text;
}
set
{
this.text = value;
}
} /// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
string EditorScript=""; EditorScript+="<input id=\""+this.UniqueID+"\" type=\"text\" value=\"\" onblur=\"CopyData();\">";
EditorScript+="<script language=javascript>";
EditorScript+="function CopyData(){";
EditorScript+="document.getElementById('"+this.UniqueID+"').value=\"\";}";
EditorScript+="</script>"; output.Write(EditorScript);
}控件要完成的功能:
      当引用该控件时,在输入框中的输入就是该控件的Text属性值,可以显示出来      引用页面:
  <form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<P><cc1:editor id="Content" runat="server"></cc1:editor></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>   引用程序:
  private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script>alert('"+Content.Text+"');</script>");
}问题:无论输入什么东东,都显示为空,请大家帮忙调一下,显示我要的功能,谢谢

解决方案 »

  1.   

    帮UP一下,分太少,没人答,但还是UP一下
      

  2.   

    没看到你给这个控件TEXT值的地方??
      

  3.   

    Response.Write("<script>alert(\""+Content.Text+"\");</script>");
      

  4.   

    ispostback属性有没有设定?否则 每次回发之后都把控件里面的内容清空了 当然没有东西了====被月亮晒黑的人=========CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2
      

  5.   

    protected override void Render(HtmlTextWriter output)
    {
    string EditorScript="";EditorScript+="<input id=\""+this.UniqueID+"\" type=\"text\" value=\"\" onblur=\"CopyData();\">";
    EditorScript+="<script language=javascript>";
    EditorScript+="function CopyData(){";
    EditorScript+="document.getElementById('"+this.UniqueID+"').value=\"\";}";
    EditorScript+="</script>";output.Write(EditorScript);
    this.PreRender +=new System.EventHandler(this.contol_Load);
    } private void contol_Load(object sender, System.EventArgs e)
    {
    //将属性值付给Text
    }
      

  6.   

    因为你的控件的Text无法从视图状态中获取值,修改Text属性如下public string Text
    {
    get
    {
    return ViewState["text"].ToString();
    } set
    {
    ViewState["text"] = value;
    }
    }另外修改这一句:
    EditorScript+="document.getElementById('"+this.UniqueID+"').value=\""+Text+"\";}";在引用此控件的页面的Page_Load里边:
    if(!Page.IsPostBack)
    {
      this.Content.Text="TextBox的值";
    }
      

  7.   

    另外如果要处理回发数据,你必须实现IPostBackDataHandler接口,参看
    http://msdn.microsoft.com/library/CHS/cpguide/html/cpconReceivingPostbackDataChangedNotifications.asp