ASP.NET自定义服务器控件无法正确呈现 [英] ASP.NET Custom Server Control Not Rendering Properly

查看:118
本文介绍了ASP.NET自定义服务器控件无法正确呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我创建了一个ASP.NET自定义服务器控件,它没有在我的测试站点中正确呈现。



控件继承自DropDownList,我试图在下拉列表中添加三个项目,如下所示:



Hello

I have created an ASP.NET custom server control and it is not rendering in my test site properly.

The control inherits from DropDownList, and I am attempting to add three items to the drop down list, as shown:

[DefaultProperty("Text")]
[ToolboxData("<{0}:YesNoDropDownList runat=server></{0}:YesNoDropDownList>")]
public class YesNoDropDownList : DropDownList
{
    public YesNoDropDownList()
    {
        this.Items.Add(new ListItem("-", "-1", true));
        this.Items.Add(new ListItem("Yes", "1", true));
        this.Items.Add(new ListItem("No", "0", true));
    }

    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("")]
    [Localizable(true)]
    public string Text
    {
        get
        {
            String s = (String)ViewState["Text"];
            return ((s == null)? "[" + this.ID + "]" : s);
        }

        set
        {
            ViewState["Text"] = value;
        }
    }

    protected override void RenderContents(HtmlTextWriter output)
    {
        output.Write(Text);
    }
}







我已成功将控件添加到网页表单和我的工具箱,但是当我运行我的测试网站时,表单上的DropDownList没有项目。



在调试项目中可以看到项目coleection,但是没有在运行时渲染到aspx页面。



有人能建议解决方案吗?



提前致谢。



Baxter-P




I have successfuly added the control to a web form, and to my toolbox, but when I run my test site the DropDownList on the form is empty of items.

In debug the items can be seen in the items coleection, but are not rendering onto the aspx page at runtime.

Can anyone suggest a solution ??

Thanks in advance.

Baxter-P

推荐答案

这篇关于ASP.NET自定义服务器控件无法正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆