473,748 Members | 6,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching Custom Events for WebUserControl

I am wondering what the best method of attaching custom Events to custom
WebUserControls are. I cannot seem to find the proper terminology to expand
my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both. I
have the client side implementation worked out. I just need to find a proper
way to to get everything registered so that the output produces something
like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
.....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance
Nov 19 '05 #1
5 4543
<jo*****@driver .net> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am wondering what the best method of attaching custom Events to
custom WebUserControls are. I cannot seem to find the proper terminology
to expand my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both. I
have the client side implementation worked out. I just need to find a
proper way to to get everything registered so that the output produces
something like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance


I hope this doesn't sound flip, but my recommendation is to go read
"Developing Microsoft® ASP.NET Server Controls and Components" from
Microsoft Press, by Nikhil Kothari and Vandana Datye
(http://www.microsoft.com/mspress/books/5728.asp).

John Saunders


Nov 19 '05 #2
if you want server side event for your ascx control then you need to define
a delegate and then define an event
e.g.

public testControl : System.Web.UI.U serControls
{
public delegate void SelectionDelega te(int selected);
public event SelectionDelega te SelectionChange d();

public void Page_Load()
{
.....
}

private void FireSelectionEv ent(int selection)
{
if(SelectionCha nged != null)
SelectionChange d(selection)
}
}
HTH

Ollie Riches
<jo*****@driver .net> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am wondering what the best method of attaching custom Events to custom WebUserControls are. I cannot seem to find the proper terminology to expand my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both. I
have the client side implementation worked out. I just need to find a proper way to to get everything registered so that the output produces something
like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance

Nov 19 '05 #3
"Ollie" <ol**********@h otmail.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
if you want server side event for your ascx control then you need to
define
a delegate and then define an event
e.g.

public testControl : System.Web.UI.U serControls
{
public delegate void SelectionDelega te(int selected);
public event SelectionDelega te SelectionChange d();

public void Page_Load()
{
.....
}

private void FireSelectionEv ent(int selection)
{
if(SelectionCha nged != null)
SelectionChange d(selection)
}
}

There is a generally-accepted pattern for events in .NET:

1) Decide on a name for the event, let's say, "SelectionChang ed"
2) Decide what information needs to be passed to listeners when the event
fires. Let's say, an integer "selection"
3) Define a derived class of EventArgs to hold this information. The class
should accept the information in its constructor, and should define a
read-only property to access the information: The name of the class should
be the name of the event followed by "EventArgs" :

public class SelectionChange dEventArgs : EventArgs
{
private int _selection;
public SelectionChange dEventArgs(int selection) : base()
{
_selection = selection;
}

public int Selection
{
get {return _selection;}
}
}

4) Define a delegate type for the event. The name of the type should be the
name of the event followed by "EventHandl er". It should return void and take
two parameters. The first should be called "sender" and should be of type
"object". The second should be called "e" and should be of your EventArgs
type:

public delegate void SelectionChange dEventHandler(o bject sender,
SelectionChange dEventArgs e);

5) Define the event:

public event SelectionChange dEventHandler SelectionChange d;

6) Define a method to fire the event. It should be protected virtual in
order to permit derived classes to handle the event efficiently, and to
allow them to raise it in a different manner. The method should be named
"On" followed by the name of the event. It should accept a single parameter
named "e", of your EventArgs type:

protected virtual void OnSelectionChan ged(SelectionCh angedEventArgs e)
{
if (SelectionChang ed != null)
{
SelectionChange d(this, e);
}
}

7) For "extra credit", you can define "convenienc e" overloads of your "On"
method. They should _not_ be virtual, but should call the virtual version:

protected void OnSelectionChan ged(int selection)
{
OnSelectionChan ged(new SelectionChange dEventArgs(sele ction));
}

8) Fire the event as required:

private void ddl_SelectedInd exChanged(objec t sender, EventArgs e)
{
OnSelectionChan ged(ddl.Selecte dIndex);
}
John Saunders

<jo*****@driver .net> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am wondering what the best method of attaching custom Events to

custom
WebUserControls are. I cannot seem to find the proper terminology to

expand
my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both. I
have the client side implementation worked out. I just need to find a

proper
way to to get everything registered so that the output produces something
like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance


Nov 19 '05 #4
I guess I did not state my real question clearly enough.
Is one supposed to be responsible for creating the attribute and
postback refreence. I had already done what was reiterated above and while
the event was declared no attribute was created for the postback.
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
.....</div>
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:OP******** ******@TK2MSFTN GP15.phx.gbl...
"Ollie" <ol**********@h otmail.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
if you want server side event for your ascx control then you need to
define
a delegate and then define an event
e.g.

public testControl : System.Web.UI.U serControls
{
public delegate void SelectionDelega te(int selected);
public event SelectionDelega te SelectionChange d();

public void Page_Load()
{
.....
}

private void FireSelectionEv ent(int selection)
{
if(SelectionCha nged != null)
SelectionChange d(selection)
}
}

There is a generally-accepted pattern for events in .NET:

1) Decide on a name for the event, let's say, "SelectionChang ed"
2) Decide what information needs to be passed to listeners when the event
fires. Let's say, an integer "selection"
3) Define a derived class of EventArgs to hold this information. The class
should accept the information in its constructor, and should define a
read-only property to access the information: The name of the class should
be the name of the event followed by "EventArgs" :

public class SelectionChange dEventArgs : EventArgs
{
private int _selection;
public SelectionChange dEventArgs(int selection) : base()
{
_selection = selection;
}

public int Selection
{
get {return _selection;}
}
}

4) Define a delegate type for the event. The name of the type should be
the name of the event followed by "EventHandl er". It should return void
and take two parameters. The first should be called "sender" and should be
of type "object". The second should be called "e" and should be of your
EventArgs type:

public delegate void SelectionChange dEventHandler(o bject sender,
SelectionChange dEventArgs e);

5) Define the event:

public event SelectionChange dEventHandler SelectionChange d;

6) Define a method to fire the event. It should be protected virtual in
order to permit derived classes to handle the event efficiently, and to
allow them to raise it in a different manner. The method should be named
"On" followed by the name of the event. It should accept a single
parameter named "e", of your EventArgs type:

protected virtual void OnSelectionChan ged(SelectionCh angedEventArgs e)
{
if (SelectionChang ed != null)
{
SelectionChange d(this, e);
}
}

7) For "extra credit", you can define "convenienc e" overloads of your "On"
method. They should _not_ be virtual, but should call the virtual version:

protected void OnSelectionChan ged(int selection)
{
OnSelectionChan ged(new SelectionChange dEventArgs(sele ction));
}

8) Fire the event as required:

private void ddl_SelectedInd exChanged(objec t sender, EventArgs e)
{
OnSelectionChan ged(ddl.Selecte dIndex);
}
John Saunders

<jo*****@driver .net> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am wondering what the best method of attaching custom Events to

custom
WebUserControls are. I cannot seem to find the proper terminology to

expand
my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both.
I
have the client side implementation worked out. I just need to find a

proper
way to to get everything registered so that the output produces
something
like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance



Nov 19 '05 #5
oh yeah so there is :)

Ollie

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:OP******** ******@TK2MSFTN GP15.phx.gbl...
"Ollie" <ol**********@h otmail.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
if you want server side event for your ascx control then you need to
define
a delegate and then define an event
e.g.

public testControl : System.Web.UI.U serControls
{
public delegate void SelectionDelega te(int selected);
public event SelectionDelega te SelectionChange d();

public void Page_Load()
{
.....
}

private void FireSelectionEv ent(int selection)
{
if(SelectionCha nged != null)
SelectionChange d(selection)
}
}

There is a generally-accepted pattern for events in .NET:

1) Decide on a name for the event, let's say, "SelectionChang ed"
2) Decide what information needs to be passed to listeners when the event
fires. Let's say, an integer "selection"
3) Define a derived class of EventArgs to hold this information. The class
should accept the information in its constructor, and should define a
read-only property to access the information: The name of the class should
be the name of the event followed by "EventArgs" :

public class SelectionChange dEventArgs : EventArgs
{
private int _selection;
public SelectionChange dEventArgs(int selection) : base()
{
_selection = selection;
}

public int Selection
{
get {return _selection;}
}
}

4) Define a delegate type for the event. The name of the type should be
the name of the event followed by "EventHandl er". It should return void
and take two parameters. The first should be called "sender" and should be
of type "object". The second should be called "e" and should be of your
EventArgs type:

public delegate void SelectionChange dEventHandler(o bject sender,
SelectionChange dEventArgs e);

5) Define the event:

public event SelectionChange dEventHandler SelectionChange d;

6) Define a method to fire the event. It should be protected virtual in
order to permit derived classes to handle the event efficiently, and to
allow them to raise it in a different manner. The method should be named
"On" followed by the name of the event. It should accept a single
parameter named "e", of your EventArgs type:

protected virtual void OnSelectionChan ged(SelectionCh angedEventArgs e)
{
if (SelectionChang ed != null)
{
SelectionChange d(this, e);
}
}

7) For "extra credit", you can define "convenienc e" overloads of your "On"
method. They should _not_ be virtual, but should call the virtual version:

protected void OnSelectionChan ged(int selection)
{
OnSelectionChan ged(new SelectionChange dEventArgs(sele ction));
}

8) Fire the event as required:

private void ddl_SelectedInd exChanged(objec t sender, EventArgs e)
{
OnSelectionChan ged(ddl.Selecte dIndex);
}
John Saunders

<jo*****@driver .net> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I am wondering what the best method of attaching custom Events to

custom
WebUserControls are. I cannot seem to find the proper terminology to

expand
my research.
Basicallly I have a custom user control that has 2 or 3 events
selectionChange d
DropDownOpened

I would like the user to be able to attach Server Side events for both.
I
have the client side implementation worked out. I just need to find a

proper
way to to get everything registered so that the output produces
something
like
<div selectionChange d="__dopostback ('contorolname' , '');"
dropdownOpened= "__dopostback(' controlname', 'dropDownOepned ????');">
....</div>

Any help or pointers would be greatly appreciated. Thanks in Advance



Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1000
by: Mike Levin | last post by:
Hello Group, I'm using VisualStudio.NET and put a DataGrid into a WebUserControl (an ascx file). For the DataGrid element, I have set AllowSorting="True" and OnSortCommand="Grid_Sort".
1
1972
by: DichkoSoft | last post by:
Hi I create WebUserControl and very confused when use control For Example: ***************************** *wuc.ascx ***************************** <script id=clientEventHandlersJS language=javascript>
2
275
by: Oren | last post by:
Hello everyone... I have a simple WebUserControl with Button and TextBox on it. Webform1.aspx contains this WebUserControl. How can I create my own C'tor for this WebUserControl - I mean when I run Webform1.aspx I want to send data to the UserControl (fill Textbox1.Text). any samples ? thanx,
2
315
by: Oren | last post by:
Hi everyone, I have WebUserControl on a Webform. How can I sent dynamically to the WebUserControl from a Function/Property on the Webform ? <uc:myuc id="myid1" CurrentPage=<%#GetText()%> data="2" runat="server"/> ..... GetText()-> function/property on the Webform, returns string and send it to the WebUserControl -> <%#GetText()%>
3
7806
by: George Jordanov Ivanov | last post by:
Folks, I am implementing a WebUserControl, which will have its own custom event StateChanged. Now, I want to add this event to the Events tab in the control properties, so that the users of my control can set the event handler from this tab. However, I can't see my custom StateChanged event over there and I don't know what is the reason. Setting BrowsableAttribute to the public event property doesn't solve the problem. Any other ideas? ...
0
915
by: Terry Olsen | last post by:
In an effort to create a QueryBuilder for a web page, I've created a WebUserControl. It can be seen here: http://boycot.no-ip.com/images/querybuilder.jpg I load one control initially in the Page_Load using this code: QueryBuilderPlaceHolder.Controls.Add(LoadControl("QueryBuilder.ascx")) I would like to have a callback routine on the main page for events such as when the user changes the "And/Or" DropDownList. If the user changed it to...
1
4348
by: Dave A | last post by:
I have a problem that I have boiled down to a very simple example. I have a user control that displays a some data from a business object. On one screen I have a collection of these business objects and wish to display the user control multiple times. On this web page I simply bind the repeater to the data source and in the ItemDataBound event dynamically load the user control via "LoadControl()". The user control contains an auto post...
0
1102
by: Klaus Jensen | last post by:
Hi In a repeater-control, in the <SeparatorTemplatei have placed a webusercontrol, I have made. That works great- However, I want to know be able to only display this WebUserControl a certain number of times. Basicly I need the WebUserControl itself to know, how many other instances of the webusercontrol was displayed on the page, when I run it.
2
2123
by: =?UTF-8?B?16jXnteZ?= | last post by:
Hey, I'm loading a webusercontrol dynamically using The following code: Control newCtrl = LoadControl("MyCtrl.ascx"); newCtrl.ID = "MyCONTROL"; container.Control.Add(newCtrl); My webusercontrol has a server-side button and it I implemented its OnClick event.
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.