Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

events 1

Status
Not open for further replies.

hjmc

Technical User
Nov 20, 2002
38
GB
Hi, can anyone help.
I have a View which contains two controls : a User Control and a button.

The button has a Click Event handler.

At a point in the code supporting the User Control I want to call the Click handler for the button.

I can get as far as addressing the button from the UserControl code using the following code:

Dim cntlPar As Control = Me.Parent /Get the View
Dim btn As Button = cntlPar.FindControl("cmdOk") /this is the button

Can some kind person help me call the Click Event I have on the button. The Click Handler has a standard look :

Protected Sub cmdOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdOk.Click



Thanks for any help.
 
the user control should not know anything about it's parent. the parent should know about the children.

if you want the button click event to do something with the child create an event handler in the page and have the button call a method on the user control.
Code:
public class MyWebUserControl : UserControl
{
   public void DoSomething()
   {
       //do something with my controls and values
       //I should have no reference to what is happening outside of me
   }
}
Code:
public class MyPage : Page
{
   protected void MyButtonClickEvent(object sender, EventArgs e)
   {
       InstanceOfMyWebUserControl.DoSomething();
   }
}
Code:
<prefix:MyWebUserControl id="InstanceOfMyWebUserControl" runat="server" />
<asp:button id="abutton" runat="server" onclick="MyButtonClickEvent" text="click me" />

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top