473,466 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Button inside a WebCustomControl not firing an event

I have built a Web Custom Control using c#, and it's pretty simple. A
dropdownlist, and a button that once clicked will render different
html. I tried attaching an event handler to the Click event of the
button and set a break point but it's never firing off it looks like. I
have tried including the INamingContainer inheritance to the class and
also adding the button to the Controls collection of the WebControl,
still nothing.

Anyone have any ideas?

Thanks,
murl

Nov 19 '05 #1
6 1767
It sounds like your button control is not getting created when it should in
order for the event to fire.

--
-Demetri
"murl" wrote:
I have built a Web Custom Control using c#, and it's pretty simple. A
dropdownlist, and a button that once clicked will render different
html. I tried attaching an event handler to the Click event of the
button and set a break point but it's never firing off it looks like. I
have tried including the INamingContainer inheritance to the class and
also adding the button to the Controls collection of the WebControl,
still nothing.

Anyone have any ideas?

Thanks,
murl

Nov 19 '05 #2
public WebCustomControl1()
{
Initialize_Components();

if ( _displayType == DisplayType.DropDownList )
// DataBind the list of available reports to the DropDownList
BindData();
}
private void Initialize_Components()
{
// ddlReports
ddlReports = new DropDownList();
// btnGenerate
btnGenerate = new Button();
btnGenerate.Click += new EventHandler( btnGenerate_Click );
Controls.Add(btnGenerate);
}
Then the rendering happens in a method that creates the html tables and
renders them to the HtmlTextWriter from the render method. Seems simple
enough :(

Nov 19 '05 #3
Create and add your controls in the CreateChildControls method by overriding
it:

e.g.
protected override void CreateChildControls()
{
btn = new Button();
btn.Text = "Click Me";
btn.Click += new EventHandler(btn_Click);
Controls.Add(btn);
base.CreateChildControls ();
}
--
-Demetri
"murl" wrote:
public WebCustomControl1()
{
Initialize_Components();

if ( _displayType == DisplayType.DropDownList )
// DataBind the list of available reports to the DropDownList
BindData();
}
private void Initialize_Components()
{
// ddlReports
ddlReports = new DropDownList();
// btnGenerate
btnGenerate = new Button();
btnGenerate.Click += new EventHandler( btnGenerate_Click );
Controls.Add(btnGenerate);
}
Then the rendering happens in a method that creates the html tables and
renders them to the HtmlTextWriter from the render method. Seems simple
enough :(

Nov 19 '05 #4
protected override void CreateChildControls()
{
btnGenerate = new Button();
//btnGenerate.ID="btnGenerate";
btnGenerate.Click += new EventHandler( btnGenerate_Click );
btnGenerate.Text = "Generate Report";
Controls.Add(btnGenerate);
base.CreateChildControls();
}

I still can't catch the event on the Server Control from the button
click, hrmmmmm

Nov 19 '05 #5
Here is my whole control and it works. Take a peek at it and see what you're
doing wrong.

[ToolboxData("<{0}:MyButtonControl runat=server></{0}:MyButtonControl>")]
public class MyButtonControl :
System.Web.UI.WebControls.WebControl,INamingContai ner
{
private Button btn;

protected override void CreateChildControls()
{
btn = new Button();
btn.Text = "Click Me";
btn.Click += new EventHandler(btn_Click);
Controls.Add(btn);
base.CreateChildControls ();
}

protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}

private void btn_Click(object sender, EventArgs e)
{
btn.Text = "I was clicked!";
}
}

--
-Demetri
"murl" wrote:
protected override void CreateChildControls()
{
btnGenerate = new Button();
//btnGenerate.ID="btnGenerate";
btnGenerate.Click += new EventHandler( btnGenerate_Click );
btnGenerate.Text = "Generate Report";
Controls.Add(btnGenerate);
base.CreateChildControls();
}

I still can't catch the event on the Server Control from the button
click, hrmmmmm

Nov 19 '05 #6
I tried just a small control exactly like what you have and it WORKED
great. I think it was the base.render methods not being called in mine.
Thanks for all of your help :)

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
1
by: Alexander Widera | last post by:
Hello, i have a webcustomcontrol (:CompositeControl) which is in an asp.net page which causes a postpack-event (ChangeSort). protected void ChangeSort(Object sender, EventArgs e) { ...
0
by: nraji | last post by:
hi, I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.