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
In code behind i did not give any thing how should I handle the event in code behind
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:
[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("<br>")); value2.TextMode = TextBoxMode.SingleLine; Controls.Add(value2); Controls.Add(new LiteralControl("<br>")); sresult.Text = "Show Result"; Controls.Add(sresult); Controls.Add(new LiteralControl("<br>")); Controls.Add(new LiteralControl("  Result: <b>")); Controls.Add(output); Controls.Add(new LiteralControl("</b>")); 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); } } }
Comment