13
Reply

Problem in Web Control Library

sam caleb

sam caleb

Feb 18 2009 11:07 PM
5.4k
Hi Friend's ...

M new to c#.net, I have created a  web control library and made to dll file but when i invoked in a web project and drag and draw that control is invisible here is that code can anyone explain me how to use that and where i have made error .....


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
 
namespace samLibray
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : WebControl
    {
        public TextBox t1 = new TextBox();
        public Button b1 = new Button();
        public Label l1 = new Label();
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

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

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(Text);
        }
        protected override void CreateChildControls()
        {
           
            l1.ID = "l1sam";
            l1.BorderColor = System.Drawing.Color.Chocolate;
            l1.Visible = true;
            Controls.Add(l1);
            Controls.Add(new LiteralControl("<Br>"));

           
            t1.ID = "t1sam";
            t1.ForeColor = System.Drawing.Color.Azure;
            t1.Visible = true;
            Controls.Add(t1);
            RequiredFieldValidator rf = new RequiredFieldValidator();
            rf.ID = "rfsam";
            rf.ErrorMessage = "Values Needed";
            rf.ControlToValidate ="t1sam";
            rf.Visible = true;
            Controls.Add(rf);

            Controls.Add(new LiteralControl("<br>"));

          
            b1.ID = "b1sam";
            b1.ForeColor = System.Drawing.Color.Blue;
         
            //buttonCell.Width = Unit.Pixel(1);
            b1.Width = Unit.Pixel(1);
            b1.Visible = true;
            Controls.Add(b1);
            Controls.Add(new LiteralControl("<br>"));
            EnsureChildControls();
            
        }
        protected override void OnInit(EventArgs e)
        {
            l1.Text = "Enter Data";
            b1.Text = "Submit";
            base.OnInit(e);
        }
        private void b1sam_Click(object sender, EventArgs e)
        {
         
    
          

        }
    }
}

Tks in Adv...

G.sam...

Answers (13)