473,770 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Handling in custom control

90 New Member
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 control.cs
Expand|Select|Wrap|Line Numbers
  1.  [DefaultEvent("Click")] 
  2. public class WebCustomControl1 : WebControl
  3. {
  4. TextBox value1 = new TextBox();
  5. TextBox value2 = new TextBox();
  6. Label output = new Label();
  7. Button sresult = new Button();
  8. private string showresult;
  9. protected override void CreateChildControls()
  10. {
  11. //base.CreateChildControls();
  12. value1.TextMode = TextBoxMode.SingleLine;
  13. Controls.Add(value1);
  14. Controls.Add(new LiteralControl("<br>"));
  15. value2.TextMode = TextBoxMode.SingleLine;
  16. Controls.Add(value2);
  17. Controls.Add(new LiteralControl("<br>"));
  18. sresult.Text = "Show Result";
  19. Controls.Add(sresult);
  20. Controls.Add(new LiteralControl("<br>"));
  21. Controls.Add(new LiteralControl("&nbsp&nbspResult:&nbsp<b>"));
  22. Controls.Add(output);
  23. Controls.Add(new LiteralControl("</b>"));
  24. sresult.Click += new EventHandler(btnsumclicked);
  25. }
  26. public event EventHandler Click;
  27. void btnsumclicked(object sender, EventArgs e)
  28. {
  29. int a = int.Parse(value1.Text) + int.Parse(value2.Text);
  30. showresult = a.ToString();
  31. }
  32.  
  33. protected virtual void onClick(EventArgs e)
  34. {
  35. if (Click != null)
  36. {
  37. Click(this, e);
  38. }
  39. }
  40.  
  41. }
  42.  
In code behind i did not give any thing how should I handle the event in code behind
Jul 18 '08 #1
1 1043
DrBunchman
979 Recognized Expert Contributor
Hi raghulvarma,

As a full member you should be aware that you need to use the [code] tags to surround your code blocks. Also you've posted this in the ASP Forum which is for Classic ASP only - I've moved it for you but please post all future ASP.NET questions in the .NET Forum.

Dr B
MODERATOR
Jul 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

18
2889
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
7730
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it calls the Parent controls CreateChildControls() method before calling the child control's button click event. Because of this behaviour, I am not getting the changes I made in the
6
1802
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I know which ImageButton caused the post back ? Does it get handled in the Page_Load or do I need to create a new event handler ? Thanks,
7
3344
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
4
7375
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to close the form via a button on the toolbar (with going to another cell in the datagrid)I want to be able to popup a messagebox to the user asking them if they want to keep their changes. At the momment I'm accomplishing this by a property that...
4
1129
by: Mike Gaab | last post by:
I am having two problems: 1. Determing the signature of event handlers for any control that raises events. I have a handle on the arguments but the method name is not clear. 2. What is the relationship between event properties and public methods listed in the VS class browser. An example will help describe this one. For example, the DataGrid has a event property named EditCommand, what is the signature of the event handler for...
6
6102
by: mj2736 | last post by:
I created a windows form control that inherits from the standard .Net DataGridView control, to which I've added custom functionality. Instead of using the standard control in my applications, I use my customized version. I have an event handler in the custom control for the KeyDown event that simulates a double-click on the selected grid row when the user presses the enter key. This is working just fine. Now, some screens that are using...
1
993
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...
2
1297
by: John Whitworth | last post by:
I'm tying myself up in knots again here. I think my query is a little different from the previous Event handling one, so have started a new thread. In VB2008, I want a reusable control, which can effectively show (and set) bit settings with true/false descriptions for each byte. Eventually, I want to group each byte into a panel, so I can treat them as a whole (and then probably put several panels into a tab control, so that a
0
9454
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
10257
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
10037
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
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
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
6710
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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

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.