DropDown List Custom Control

S

Steven

This one should be a fairly simple one for you guys. I want to create a
small dropDown list (custom control) and when the user selects anyone of the
value, the control should pass back the Selected Value. This is what I did
till now and I do not know how to pass back the selected value .. Please
help

public class DDControl : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
{
protected override void Render(HtmlTextWriter output)
{
string s1 = "<SELECT NAME=\"pizzasize\">" ;
string s2 = "<OPTION VALUE=\"s\">" ;
string s3 = "small";
string s4 = "<OPTION VALUE=\"m\">" ;
string s5 = " medium" ;
string s6 = "<OPTION VALUE=\"l\">" ;
string s7 = "large" ;
string s8 = "</SELECT>" ;
output.Write(s1+s2+s3+s4+s5+s6+s7+s8) ;
}
public event EventHandler DropDownChange;

public void RaisePostBackEvent(string eventArgument)
{
OnDropDownChange(EventArgs.Empty);
}

protected virtual void OnDropDownChange(EventArgs e)
{
if (DropDownChange != null)
{
DropDownChange(this, e);
}
}

}

Thanks
Steven
 
K

Karl Seguin

There's a much better way to do this...you are reinventing too much on the
plumbing...

why not just create a control which inherits from DropDownList and add the 3
list items?

public class DDControl : DropDownList{
protected override void CreateChildControls(){
Items.Add(new ListItem("small", "s"));
Items.Add(new ListItem("medium", "m"));
Items.Add(new ListItem("large", "m"));
base.CreateChildControls ();
}
}

Karl
 
S

Steven

Hello Karl,

Thanks for your reply!

The control I'm creating will contain many child controls like textboxes,
buttons and dropdownlists. I just split my code into small module, where I
just want to create Dropdownlist and raise the postback event. Could you
please explain me on how to do that?

Thanks
Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top