How to Create a web control library
Hi Frnd's..
I'm New to C#.net.Can anyone say how to Create a web control library
in C#.net Step by Step Process...
Tks In Adv...
G.Sam...
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
LisaPosted Feb 17, 2009, 8:58 AM
say for example you created a namespace called samLibray u then need to add the dll to refrence in your project you want to call and add the namespace
using samLibray in the class you want to use.
then you can create an object instance of the class like
samLibray sl1 = new samLibray();
and use the methods and variables using sl.onInit() etc..
Thanks,
Lisa
LisaPosted Feb 17, 2009, 8:52 AM
all the protected and private methods and variables will be invisible, you can only access public methods by referencing to the dll unless the class is a derived class of the parent class.
I hope it helps.
Thanks,
Lisa
sam calebPosted Feb 17, 2009, 8:43 AM
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;
Controls.Add(l1);
Controls.Add(new LiteralControl("
"));
t1.ID = "t1sam";
t1.ForeColor = System.Drawing.Color.Azure;
Controls.Add(t1);
RequiredFieldValidator rf = new RequiredFieldValidator();
rf.ID = "rfsam";
rf.ErrorMessage = "Values Needed";
rf.ControlToValidate ="t1sam";
Controls.Add(rf);
Controls.Add(new LiteralControl("
"));
b1.ID = "b1sam";
b1.ForeColor = System.Drawing.Color.Blue;
//buttonCell.Width = Unit.Pixel(1);
b1.Width = Unit.Pixel(1);
Controls.Add(b1);
Controls.Add(new LiteralControl("
"));
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...
LisaPosted Feb 17, 2009, 7:28 AM
sorry, but i cant read any of your code its all messed up and do tell me what error are you getting stuck at ?
but taking a closer look at it , it looks like you set all of your functions to protected level, which i doubt will not allow you to access unless it is a derived class so try changing it to public methods
it should work.
Thanks,
Lisa
sam calebPosted Feb 17, 2009, 7:01 AM
")); t1.ID = "t1sam"; t1.ForeColor = System.Drawing.Color.Azure; Controls.Add(t1); RequiredFieldValidator rf = new RequiredFieldValidator(); rf.ID = "rfsam"; rf.ErrorMessage = "Values Needed"; rf.ControlToValidate ="t1sam"; Controls.Add(rf); Controls.Add(new LiteralControl("
")); b1.ID = "b1sam"; b1.ForeColor = System.Drawing.Color.Blue; //buttonCell.Width = Unit.Pixel(1); b1.Width = Unit.Pixel(1); Controls.Add(b1); Controls.Add(new LiteralControl("
")); 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...
LisaPosted Feb 17, 2009, 6:54 AM
did you meant a class library??
if it is then just go to new project and select the option Class Library under the windows in your selected environment and you can start designing the library as and how you need.
Thanks,
Lisa