相关疑难解决方法(0)

用户控件,服务器控件和自定义控件之间有什么区别?

在最近的一次采访中,我认为我对这个问题有合理的答案,但我对此进行了轰炸.:(

  • 这三者之间有哪些主要区别?
  • 如果前一个子弹的答案不明显,你什么时候选择一个?

asp.net user-controls controls custom-controls

15
推荐指数
2
解决办法
2万
查看次数

WebControl和CompositeControl之间的区别?

我一直在网上浏览并找到一些关于这个主题的文章,但我仍然无法弄清楚它们之间的区别.我有下面的代码显示,如果我从CompositeControl继承它完美的工作但不是如果我从WebControl继承.(它们都呈现代码,但只有CompositeControl处理事件)

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestLibrary
{
    public class TemplateControl : CompositeControl
    {
        TextBox txtName = new TextBox();
        TextBox txtEmail = new TextBox();
        Button btnSend = new Button();

        private void SetValues()
        {
            btnSend.Text = "Skicka";
        }

        protected override void CreateChildControls()
        {
            SetValues();

            this.Controls.Add(new LiteralControl("Namn: "));
            this.Controls.Add(txtName);
            this.Controls.Add(new LiteralControl("<br />"));
            this.Controls.Add(new LiteralControl("Email: "));
            this.Controls.Add(txtEmail);
            this.Controls.Add(new LiteralControl("<br />"));
            btnSend.Command += new CommandEventHandler(btnSend_Command);
            this.Controls.Add(btnSend);
        }

        void btnSend_Command(object sender, CommandEventArgs e)
        {
            this.Page.Response.Write("Du har nu klickat på skicka-knappen! <br /><br />"); …
Run Code Online (Sandbox Code Playgroud)

c# events composite web-controls composite-controls

8
推荐指数
1
解决办法
4261
查看次数