I'm novice and i would like to know that how can we handle the events like TextChanged event for the text box, OnClick Event for the button control, etc.
Please help me
Thanks in advance
Thanks
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
Double click a button on your page and you will automatically go to the onclick event handle for that button. You can then write code to be excecuted when that button is clicked.
In general
If you right click a control, let it be a button, textbox or dropdownlist or radiobuttonlist and select properties, you see a yellow "thing", move the mouse over that yellow "thing" and you will see a tooltip saying 'events'. If you click it, you will see
all events that can be handled for that control. So just double click in the column at the right of the event you want to handle and you will be right in its event handle and you can start writing your code there.
--------------------------------------------------
Sincerely,
Nick
ASP.NET, SQL Server [Database Engine, SSIS & SSRS],Entity Framework, C# and VB.NET
I've done this but when double clicking the custom control button I'm not getting the text changed event even though I'm getting in the Properties event field
Thanks
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
I guess what you are talking about is the user controls which can add server controls in the ascx page. You can assign the handle method attribute with the method name in the tag. The following one is a sample. For more information about usercontrol, plsase
visit
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx
If you are referring to a Custom Server Control and not a User Control, as I think you are, then perhaps this will help.
Say you have a Custom Server Control that is a composition of a ListBox and a Button on a Panel. Your custom server control class would probably look like this
public class MyCustomListBox : Panel, INamingContainer
{
protected ListBox MyListBox;
protected Button DeleteButton;
...
. In order to handle the events of the sub controls (ListBox and Button), you need to register Event Handlers for them.
To do this you basically need a method in your custom control of the right signature (object o, EventArgs e), then create a delegate and assign it to the correct event using event registering operator (+=).
e.g to capture the Click event of the button, you would create your handler method in the custom control (MyCustomListBox) class
protected void MyButton_Click(object sender, EventArgs e)
{
//do stuff to handle event here
}
then register the handler on the button when you are adding the control to your panel in the CreateChildControls method you will be overriding.
e.g.
protected override void CreateChildControls()
{
MyButton = new Button(); //create the button object
MyButton.Text = "Delete item"; //modify any properties you want
MyButton.Click += new EventHandler(this.AddRightButton_Click); //Create a delegate for the handler function and add/register it on the Click event
this.Controls.Add(MyButton); //Add the button to the this (ie. to the panel)
//more child controls stuff
//..
}
When the control is added to a page and displayed the button will be displayed as part of the panel. When the user clicks on the button the Click event will fire and your MyButton_Click method will be called.
NB: The name of the button handler is not important, you could call it Fred, just so long as it has the correct signature e.g. protected void Fred(object o, EventArgs e)
I think it would be polite to first acknowledge some of the people who have already offered you advice on this topic - othwise, I suspect you will not be getting much more help in the future.
Sorry For my attitude. Actually before getting your suggestion, I've done the work. But after getting your suggestion, i realized so. I'm late to say thanx but still I want to say thanks.
Again Sorry
Thanks
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
There a bit of problem in my button custom control who can act like hyperlink and simple button, When idouble click over it, the cursor goes no where in the .aspx.cs page. means to say the the wvent is not handled by the double click over the control.
Although it is working fine by attaching it in the OnInit()method
akyash
Member
86 Points
50 Posts
Custom Control Event Handling Problem
Jun 07, 2007 12:12 PM|LINK
Hi,
I'm novice and i would like to know that how can we handle the events like TextChanged event for the text box, OnClick Event for the button control, etc.
Please help me
Thanks in advance
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
Nick Asiimwe
Participant
1459 Points
643 Posts
Re: Custom Control Event Handling Problem
Jun 07, 2007 01:42 PM|LINK
The short-cut.
Double click a button on your page and you will automatically go to the onclick event handle for that button. You can then write code to be excecuted when that button is clicked.
In general
If you right click a control, let it be a button, textbox or dropdownlist or radiobuttonlist and select properties, you see a yellow "thing", move the mouse over that yellow "thing" and you will see a tooltip saying 'events'. If you click it, you will see all events that can be handled for that control. So just double click in the column at the right of the event you want to handle and you will be right in its event handle and you can start writing your code there.
Sincerely,
Nick
ASP.NET, SQL Server [Database Engine, SSIS & SSRS],Entity Framework, C# and VB.NET
akyash
Member
86 Points
50 Posts
Re: Custom Control Event Handling Problem
Jun 11, 2007 06:09 AM|LINK
hi,
I've done this but when double clicking the custom control button I'm not getting the text changed event even though I'm getting in the Properties event field
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
Nai-Dong Jin...
All-Star
41630 Points
3558 Posts
Re: Custom Control Event Handling Problem
Jun 13, 2007 09:51 AM|LINK
Hi,
I guess what you are talking about is the user controls which can add server controls in the ascx page. You can assign the handle method attribute with the method name in the tag. The following one is a sample. For more information about usercontrol, plsase visit http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
protected void Button1_Click(object sender, EventArgs e)
{
}
Thanks.
.
akyash
Member
86 Points
50 Posts
Re: Custom Control Event Handling Problem
Jun 13, 2007 10:53 AM|LINK
Hi,
You mean to say that We can't do the event handling using the custom server control???
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
SurfJunkie
Member
4 Points
3 Posts
Re: Custom Control Event Handling Problem
Jun 13, 2007 04:42 PM|LINK
If you are referring to a Custom Server Control and not a User Control, as I think you are, then perhaps this will help.
Say you have a Custom Server Control that is a composition of a ListBox and a Button on a Panel. Your custom server control class would probably look like this
public class MyCustomListBox : Panel, INamingContainer { protected ListBox MyListBox; protected Button DeleteButton;...
. In order to handle the events of the sub controls (ListBox and Button), you need to register Event Handlers for them.
To do this you basically need a method in your custom control of the right signature (object o, EventArgs e), then create a delegate and assign it to the correct event using event registering operator (+=).
e.g to capture the Click event of the button, you would create your handler method in the custom control (MyCustomListBox) class
akyash
Member
86 Points
50 Posts
Re: Custom Control Event Handling Problem
Jun 14, 2007 07:53 AM|LINK
Hi,
I've sorted out the problem. Now, can anyone suggest me that how can i make radio and check box custom controls
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
SurfJunkie
Member
4 Points
3 Posts
Re: Custom Control Event Handling Problem
Jun 14, 2007 12:49 PM|LINK
Ajeet,
I think it would be polite to first acknowledge some of the people who have already offered you advice on this topic - othwise, I suspect you will not be getting much more help in the future.
akyash
Member
86 Points
50 Posts
Re: Custom Control Event Handling Problem
Jun 19, 2007 07:46 AM|LINK
Hi,
Sorry For my attitude. Actually before getting your suggestion, I've done the work. But after getting your suggestion, i realized so. I'm late to say thanx but still I want to say thanks.
Again Sorry
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.
akyash
Member
86 Points
50 Posts
Re: Custom Control Event Handling Problem
Jun 26, 2007 11:15 AM|LINK
Hi,
There a bit of problem in my button custom control who can act like hyperlink and simple button, When idouble click over it, the cursor goes no where in the .aspx.cs page. means to say the the wvent is not handled by the double click over the control. Although it is working fine by attaching it in the OnInit()method
protected override void OnInit(EventArgs e){
this.AKS_Button1.Click +=new EventHandler(AKS_Button1_Click);base.OnInit(e);}
this code is working fine, but not the double click.thanks in advance
"custom control"
Ajeet kumar
.................................................
Please click "Mark as Answer" on the posts that help you.