Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2004, 08:27 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control

I have a user control I created with two text boxes and a button. Is there a way I can have the page I put the user control on handle the button_Click event?
 
Old May 28th, 2004, 08:43 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if a user control raises events that you want the page to respond to, you should include the WithEvents keyword in the declaration. Then, you can create an event procedure for the event within the code-behind file for the page.
 
Old May 28th, 2004, 09:27 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Take a look at this thread. Look for the 6th post, the one with the diagram in it. That post explains the concept of event bubbling.
 
Old May 28th, 2004, 09:55 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

This is the relevent code for what I currently have:

‘User Control Code:

Protected WithEvents btnLogin As System.Web.UI.WebControls.Button
Public Event LoginClick As EventHandler

Protected Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        RaiseEvent LoginClick(Me, e)
    End Sub

‘Page Code:
Protected WithEvents LoginComponent As LogIn

Protected Sub Process(ByVal sender As Object, ByVal e As EventArgs) Handles LoginComponent.LoginClick
        sender.BackColor = Color.Blue
    End Sub

I've set break points on both btnLogin_Click and Process however, it only makes it to btnLogin_Click. Why would it skip calling the sub routine from the page?
 
Old May 28th, 2004, 11:02 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not sure what the problem is. What you have looks correct. I just did a test with practically the same thing, and it worked for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
user control in user control prijatelce ASP.NET 2.0 Basics 2 May 2nd, 2008 08:42 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM
Help with control initialization in user control mike_remember ASP.NET 1.0 and 1.1 Professional 7 December 19th, 2005 11:08 AM
User Control stu9820 ASP.NET 1.0 and 1.1 Basics 20 July 20th, 2004 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.