GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Microsoft  >  ASP.NET 2.0
Go To First  |  Previous Question  |  Next Question 
 ASP.NET 2.0  |  Question 155 of 159    Print  
Handling events 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


Code: ( text )


[DefaultEvent("Click")]

public class WebCustomControl1 : WebControl

{
TextBox value1 = new TextBox();

TextBox value2 = new TextBox();

Label output = new Label();

Button sresult = new Button();
private string showresult;

protected override void CreateChildControls()

{

//base.CreateChildControls();

value1.TextMode = TextBoxMode.SingleLine;

Controls.Add(value1);

Controls.Add(new LiteralControl("
"));

value2.TextMode = TextBoxMode.SingleLine;

Controls.Add(value2);

Controls.Add(new LiteralControl("
"));

sresult.Text = "Show Result";

Controls.Add(sresult);

Controls.Add(new LiteralControl("
"));

Controls.Add(new LiteralControl("  Result: "));

Controls.Add(output);

Controls.Add(new LiteralControl("
"));

sresult.Click += new EventHandler(btnsumclicked);

}

public event EventHandler Click;

void btnsumclicked(object sender, EventArgs e)

{

int a = int.Parse(value1.Text) + int.Parse(value2.Text);

showresult = a.ToString();

}


protected virtual void onClick(EventArgs e)

{

if (Click != null)

{

Click(this, e);

}

}

}



In code behind i did not give any thing how should I handle the event in code behind



  
Total Answers and Comments: 1 Last Update: October 22, 2008     Asked by: raghulvarma 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 22, 2008 04:43:08   #1  
rajesh550 Member Since: July 2008   Contribution: 1    

RE: Handling events in custom control
First you may build the control ex Button b = new Button(); b.Text = "ex"; Then you add the button to other control right ? like this.control.add(b); but before add the button (b) to other control, you add the even to the button (b) because its a button, then it will have even onclick, then you add code b.Click +=new EventHandler(b_Click); b_Click is a function or even handler you want to add, if the button (b) clicked.
 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : User control create for GUI purpose and it is form  of .ascx  and in aspx page you need to specify the src (Path) of the control.Custom control is form of compiled form (assembly). For using this control you need to add referenct in your project. In ...

Latest Answer : State Server is used for handling sessions in a web farm. In a web farm, make sure you have the same in all your web servers. Also, make sure your objects are serializable. For session state to be maintained across different web servers in the web farm, ...

In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events?

Latest Answer : Dataadapter1.Fill(ds) where ds is the dataset object name and fill() method is used to fill the dataset from the dataadapter ...

Latest Answer : Yep, Sure. In ItemdataBound event, you can play data as you wish. ...

Latest Answer : itemtemplate ...

Latest Answer : ...

What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?

Latest Answer : ControlToValidate property and Text property ...

Which control would you use if you needed to make sure the values in two different controls matched?


 Sponsored Links

 
Related Articles

Using XMLType for Handling XML Data in the Database

Using XMLType for Handling XML Data in the Database Being an object type XMLType can not only be used to store XML data in the database but also to operate on that data via its built in methods Regardless of the storage model you choose XMLType provides a set of XML specific methods to operate on XM
 

ODP.NET - Handling Nulls when Working with OracleDataReader

ODP NET Handling Nulls when Working with OracleDataReader When we work with OracleDataReader or for that matter even with data rows in a data table we may come across nulls The following is the efficient way to deal in with such scenarios mosgoogle geshibot language VB NET" create connect
 

ODP.NET - Handling Nulls when Executing with ExecuteScalar

ODP NET Handling Nulls when Executing with ExecuteScalar The most important issue to remember is that ExecuteScalar simply returns an object type of data The object refers to any data type within NET If the data type of your variable matches with the type of object returned by ExecuteScalar an impli
 

High Level Data Link Control (HDLC)

High Level Data Link Control HDLC The High Level Data Link Control protocol was developed by the International Organization for Standardization ISO It is used for switched and non switched networks and is a bit oriented architecture The High Level Data Link Control has been accepted and used widel
 

Synchronous Data Link Control (SDLC)

Synchronous Data Link Control SDLC The SDLC or the Synchronous Data Link Control was first developed by IBM It is basically a linked layer protocol which can be used with systems network architecture or the SNA environment In this system all the functions in a network can be defined and slotted into
 

ERP Operation and Control

ERP Operation and Control The selection of the most suitable management system is it a difficult decision to make but once it is decided the next step is the operation and maintenance of ERP It is necessary to know well all the capacities and abilities in order to exploit the system to its fullest e
 

ERP Systems as Quality Control Support

ERP Systems as Quality Control Support For the past few years ERP systems have became one of the most powerful tools for quality control management But ERP is just an informatics system that provides support to the integrated business management mosgoogle center Goals of the Quality Control Module i
 

C++ String Representation and Handling

C String Representation and Handling In this C tutorial you will learn about string representation and handling how is string represented end string notation initializing char array character representation string literals example programe to understand the character array concept and the accessing
 

String handling functions

What is the string handling functions present in header file <string.h>? There are number of string handling functions present in string.h. In other words if a programmer uses any of the function present in string.h then they must include the header file as #include <string.h&am
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape