Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VS2010 I am new to develop Custom controls,actually i developed sample custom control with one textbox and i got the proper solution i want to go a step forward means to develop custom control with multiple controls (textboxes, drop down list, and checkbox) can any one help me with proper example in detail.

below i am adding my sample custom control code

1) start -->vs 2010 --> File --> New website --> Provide Name --> Ok
2) solution explorer -->rc on solution --> add --> web server control --> provide name then click on ok
3) it opens the window in that window paste below code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ServerControl1
{

[DefaultProperty("ch")]
[ToolboxData("<{0}:ValidTextBox1 runat=server></{0}:ValidTextBox1> <{1}:ValidTextBox2 runat=server></{1}:ValidTextBox2>")]

public class ValidTextBox1 : TextBox
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string ch
{
get
{
String s = (String)ViewState["ch"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["ch"] = value;
}
}
private RequiredFieldValidator rfv;
public string NotValid;
public string C_Script = "true";


protected override void RenderContents(HtmlTextWriter op)
{
op.Write(ch);
base.RenderContents(op);
rfv.RenderControl(op);
}
}
}

Build the solution

add new item to web site

add reference of web server control to the website as given below.

rightclick on website--> add reference --> projects --> select the custom control name -->click on ok.

new we can use the custom control in web site just paste the below code in web form

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServerControl1;

public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
ValidTextBox1 txt = new ValidTextBox1();
pnl1.Controls.Add(txt);
}

}

}


build and execute u wil get one text box as outpot

But i wand to develop custom control with multiple controls can any one help its urgent its my task for the client requirement.
Posted

1 solution

 
Share this answer
 
Comments
Member 11060495 26-Sep-14 8:28am    
Thank you for your help but actually i am searching for custom control with multiple controls in asp.net using c#
[no name] 26-Sep-14 8:32am    
Ok buddy. Let me try then . Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900