473,396 Members | 1,713 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,396 software developers and data experts.

Event Handling in custom control

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 1023
DrBunchman
979 Expert 512MB
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
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...
3
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...
6
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...
7
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,...
4
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...
4
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...
6
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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
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...
0
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,...

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.