Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a web page in C# 2.0 that i made using studio 05. This page has a user control in it with a button on it. I want the page to be able to tell when the button in the user control is clicked.

Can this be done?

I googled it and found a few conflciting articles about what event bubbling is as opposed to event delegation. All of the sample code I found was for asp.net 1.1

Folks were adding event delegations in the code. Correct me if I'm wrong but that has changed significantly with the partial class code model, hasn't it?

 

I mean I can't even see my InitializeComponent code can I? Where is the rest of the partial class? Is it created in memory at runtime? If so how can I latch events on?

Wanna-Be C# Superstar
  • Administrators
Posted

You should be able to handle the click event for the button within the control and then get this to raise an event defined by the control.

The introduction of partial classes should really affect your ability to add an event handler, also rather than declaring a new delegate you could simply use the System.EventHandler if you do need to pass any information or if you do then .Net 2.0 also defines a generic to simplify the declaration (the name of it escapes me at the moment though ;)).

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I kind of get what you are saying but I can't make it work without seeing it.

 

I have a button inside my control and I handle the click event of that just fine. But I want my parent page to be able to respond to this as well. Basically I want to hide the control after the button inside of it has been clicked.

So I register an event inside my control like this

 

public event EventHandler ReviewSubmitted; //public event
   private void OnReviewSubmitted(object sender, EventArgs e)
   {
       ReviewSubmitted(sender, e);
   }

 

and after the button inside is done doing its business i call

 

OnReviewSubmitted(this, EventArgs.Empty);

 

That will compile fine but I know i need another piece in the parent aspx page to handle the call to that event.

 

But when i highlight my user control in design view i get no lightning bolt in the properties so how do i define an event?

 

I think I'm close i'm just a little clueless.

Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...