|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
The problem is as follows:
I need to create a number of buttons, which is not known in advanced and will depend on the number of rows in the table. Further on, each button should have a function, which takes the information from that row, where the button is and do something to it. At the moment I am just trying to make a button that will change the text of the label, just to see if it works. The way I am doing it is- I am creating a new Button class extending WebControls.Button and overriding onClick( e)method. When I test it, I can see that the button is created exactly the way I wanted it to be, but when I click the method is not executed, the program never goes into it(I set the brake points to check it). It is obvious that the default method is executed instead, but why? Should I do anything with delegates instead? This is the code example: //aspx.cs file //the button is created automaticaly, as many times as needed protected System.Web.UI.WebControls.Label lab; if(j==3) { Buttonnn btn=new Buttonnn(lab); btn.Text="Edit_"+name; c.Controls.Add(btn); } //Buttonnn class using System; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.ComponentModel; namespace WebSolve { public class Buttonnn:System.Web.UI.WebControls.Button { protected System.Web.UI.WebControls.Label lab; public Buttonnn(System.Web.UI.WebControls.Label lab) { this.lab=lab; base.BorderWidth=6; } protected override void OnClick(EventArgs e) { lab.Text+="Clicked"; base.OnClick(e); } } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > C# and ASP.NET create a new Button Class |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|