Answered by:
Trying to expose an event on a web user control to the designer

Question
-
User-2105009887 posted
I am creating a web user control that has several server controls on it, like Buttons and LinkButtons. I have created several public properties in the web user control for use during design mode, and these show up nicely in the designer's Properties panel just fine. I would like to do the same for an event I created in the web user control. I can't seem to get it to be "seen" in the designer. Is this even possible to do with a web user control, and, if so, what are the steps?
Thanks a lot!
P.S. I am working in Visual Web Developer 2008, if that makes a difference.
Tuesday, June 24, 2008 1:23 AM
Answers
-
User1187105292 posted
I created a class library project and created a custom control in it. I defined an event per my prior post. (I didn't write the code to make the event do something as you already know how to do that.) I compiled the class library.
Then I went to my web app and added the class library as a reference.
I added the control to the toolbar (because vs2005 is "irregular" in performing that task), then dragged the control to a webpage.
Right click to properties on the control, press the event button and there was the event in the list.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 25, 2008 3:20 AM
All replies
-
User-1301077487 posted
here is what u can do
create an event of ur user control
Partial Class usercontrol
Inherits System.Web.UI.UserControlPublic Event control_event As control_delegate
Public Delegate Sub control_delegate(ByVal sender As Object, ByVal e As EventArgs)------------------------->delegate
attach a handler to ur event
Protected Sub page_init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
AddHandler control_event, AddressOf _controlHandler
End Sub
now suppose u need to raise this event on button click u just need to raise this event in button click handler
like this
protected void Button1_Click(object sender, EventArgs e)
{
RaiseEvent control_event(me,e)
}
and handle it with its handler
like this
Protected Sub _controlHandler(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SliderTextChange
//user control handler add your code here
End Sub
Tuesday, June 24, 2008 1:44 AM -
User1187105292 posted
I created a TextBox variable in one of my C# classes and did a Go To Definition on it.
This is what I found:
public event EventHandler TextChanged;
Doing the same trick in VB should work.
Best I can do for you besides that is to suggest you read the chapters on event handlers in the language you are using. (That's what I would have to do to get farther!) Hope this helps you on your way!
Tuesday, June 24, 2008 1:44 AM -
User-2105009887 posted
Thanks for the replies, but each reply so far sort of misses the mark in its own way. I already know how to create a delegate and an event and raise the event (I use C# by the way.) And I've been scouring MSDN and books but keep coming up short there.
What I want to make happen is that, in Visual Studio, after my web user control is dragged onto an .aspx page, you should be able to click on it and then go to the properties panel for it and set various value properties I created (this part works already) and also click on the Events (Lightning bolt) button and see an event listed there that I created (right now, the Events button never even lights up.) Double clicking in that entry would create an event handler stub in the current .aspx.cs file so you can code what to do based on the event args that I pass in.
Is this possible to do for a web user control (obviously the data properties its possible for, but I mean the event part)? If not, I guess I have to create a server control from scratch, but if it is possible, what do I need to do?
Tuesday, June 24, 2008 11:13 AM -
User1187105292 posted
I created a class library project and created a custom control in it. I defined an event per my prior post. (I didn't write the code to make the event do something as you already know how to do that.) I compiled the class library.
Then I went to my web app and added the class library as a reference.
I added the control to the toolbar (because vs2005 is "irregular" in performing that task), then dragged the control to a webpage.
Right click to properties on the control, press the event button and there was the event in the list.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 25, 2008 3:20 AM -
User-2105009887 posted
Thank you. I guess the answer is that it can only be done by creating a custom control in a class library and can't be done for a straight web user control. I'm kinda confused as to why, though, since either way the control will have the same inheritance. But, again, thanks.
Wednesday, June 25, 2008 10:31 AM -
User1187105292 posted
I guess the answer is that it can only be done by creating a custom control in a class library and can't be done for a straight web user control. I'm kinda confused as to why, though, since either way the control will have the same inheritance.
Sorry, I normally only do custom controls, so I can't say one way or the other.
Thursday, June 26, 2008 1:33 AM -
User-342808847 posted
The answer is NO you cannot see the events in your Properties window. Check out http://bytes.com/forum/thread474190.html.
Wednesday, August 20, 2008 6:09 PM