473,765 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to create Custom WebControl with Button click event method

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
button in that panel that should be associated with a event method - but it
isn't working:
protected override void Render(HtmlText Writer output)
{
Panel panel = new Panel();
nextButton = new Button();
nextButton.Text = "Submit";
nextButton.Clic k += new EventHandler(ne xtButtonClick);
nextButton.Visi ble = true;
panel.Controls. Add(nextButton) ;
Controls.Add(pa nel);
panel.RenderCon trol(output);
}

I should add that this Custom WebControl may eventually contain multiple
Panels - is this the proper inheritance for this Custom WebControl:
public class SurveyWebContro l : System.Web.UI.W ebControls.WebC ontrol,
System.Web.UI.I NamingContainer

Thanks,
Novice
Nov 18 '05 #1
2 5928
Shouldn't you be doing it at the OnLoad() override? (checking for postback
of course)..
--
Girish Bharadwaj
http://msmvps.com/gbvb
"Novice" <6tc1ATqlinkDOT queensuDOTca> wrote in message
news:24******** *************** ***********@mic rosoft.com...
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
button in that panel that should be associated with a event method - but it isn't working:
protected override void Render(HtmlText Writer output)
{
Panel panel = new Panel();
nextButton = new Button();
nextButton.Text = "Submit";
nextButton.Clic k += new EventHandler(ne xtButtonClick);
nextButton.Visi ble = true;
panel.Controls. Add(nextButton) ;
Controls.Add(pa nel);
panel.RenderCon trol(output);
}

I should add that this Custom WebControl may eventually contain multiple
Panels - is this the proper inheritance for this Custom WebControl:
public class SurveyWebContro l : System.Web.UI.W ebControls.WebC ontrol,
System.Web.UI.I NamingContainer

Thanks,
Novice

Nov 18 '05 #2
Hello Girish,

Anywhere prior to/including OnPreRender should be fine... You're right, Render isnt the place for this...

--
Matt Berther
http://www.mattberther.com
Shouldn't you be doing it at the OnLoad() override? (checking for
postback of course)..


Nov 18 '05 #3

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

Similar topics

1
1651
by: Owatona | last post by:
Hi to all... I have 3 classes derived from webcontrol. I the first i have two dropdownlist, in the second i have some buttons, and the third its the webcontrol that are instanciate the two first... I would like to know what is the best way to comunicate elements that are placed in differents webcontrol... for instance... if i have a webcontrol that has a button, and another webcontrol that has a label, what its the best option to...
1
2939
by: Marri Suliez | last post by:
Does anyone know how the Style property of the WebControl class persists between calls as if it's added to the ViewState? CssStyleCollection is not serializable. The following scenario leads me to believe it is being stored in ViewState somehow: 1. Add a TextBox and a Button to a form 2. Have the Button.Click event add value to the TextBox.Style collection 3. Add a breakpoint in the Button.Click event handler immediately before the...
4
2126
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 Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
1
2629
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click inside the server control when it is clicked on. however when I click on a button at present I get an error saying that the An error has occurred because a control with auto-generated id
0
2955
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 such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
0
1905
by: OceanBreeze | last post by:
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The table gets successfully displayed on the browser with the LinkButton. When I click on the link button in the browser, my control does not go inside the custom even that I wrote for the link button. I have a table control as ProviderTbl in which...
0
994
by: Steven C | last post by:
Hello: I have a Windows Forms datagrid, which is populated with data from a SQL Server database. On that grid, I have both an EDIT button and a DEL button. I used code to wire up a custom event handler for the grid, such that it calls a method (m_HandleGridDelButton) in the class to process a delete. My problem has been that the event handler fires off more than once (I click the DEL button on one row, and several rows are deleted). ...
0
1156
by: JohnK82 | last post by:
Hi guys I have a webcontrol that displays an article in multiple parts. You can jump back and forward between the parts (I call them sheets) by clicking on a label. Each sheet has a label. The control is used like this: <john:MyControl runat="server"> <john:Sheet label="Intro"> This is the first part of the text... </john:Sheet>
1
1043
by: raghulvarma | last post by:
I have created a custom control to get the values and sum them, Here I am able to get display the controls but I am not able to add the values in the text box which means that I am not able to catch the event handling function how is it to be done and my second question is when I press the sum button the values in the textbox gets erased should I need to set the viewstate property if so how should i do that? below shown is my code custom...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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 we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.