473,289 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Event Handler for button click in Custom WebControl

Hey all, I've already posted this question and two posters offered
suggestions and they worked - but now I would like to know why - and if
possible the answer to a second question.

Here is my problem:
I am trying to write a custom WebControl - at some point this WebControl
will output a bunch of controls into several Panel objects. But I just
recently got my WebControl to output a single button and attach an event
handler to that button (thanks to those two posters).

Here is the code I previously had:
protected override void Render(HtmlTextWriter output)
{
Panel panel = new Panel();
nextButton = new Button();
nextButton.Text = "Submit";
nextButton.Click += new EventHandler(nextButtonClick);
nextButton.Visible = true;
panel.Controls.Add(nextButton);
Controls.Add(panel);
panel.RenderControl(output);
}

So it was then suggested that I move this code into the OnLoad - which I did
(except for the "panel.RenderControl(output);" line) and it worked.

The signature for my class is:
public class ReportWebControl : System.Web.UI.WebControls.WebControl,
System.Web.UI.INamingContainer

So my first and most important question:
1. How should I be creating and outputting multiple controls (buttons, text
fields, etc) onto a web page from within a webcontrol (exp - should I make
all of the controls that I will output a member variable of my class, should
I put all of the creation of those controls in the OnLoad method and then
output all the panels in the Render method)?

2. Why does the event handler get "lost" when I put the event handler
association within the Render method?

Thanks,
Novice

Nov 18 '05 #1
0 1785

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

Similar topics

1
by: Divya | last post by:
Hello This is my 1st project where I have to create a Webcontrol. I have created a simple custom control with a button and 2 labels added to a panel. My problem is that the event handler that I...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Novice | last post by:
I can't seem to get my Custom WebControl to output a button whose click event is associated with a particular method. Here is the code I have right now that contains a panel and there is a...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
0
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi, I have built a custom control button which inherits from WebControl and implements IPostBackEventHandler. The control also declares an event Click and provides a method OnClick which invokes...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.