Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 April 7th, 2004, 08:19 AM
Registered User
 
Join Date: Feb 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing a user control properties

I've got a user control that contains a DropDownList and nothing else. It has code behind(VB) that gets information from a database and a property called ValueID so that I can pass it the default item from the parent page. This all works fine and selects the correct item in the dropdown.

What I cannot get to work and have tried always, is if I change the selecteditem I want to get the value and use it on the parent page, which also uses codebehind(VB) to that I can update the database.

Thanks for any help provided
 
Old April 7th, 2004, 08:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can't you expose another public property that provides this information? When the SelectedIndex changes, retrieve the new value and store it in a private variable.
A public property can then provide access to this private value.

Does that make sense?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 7th, 2004, 08:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to create a public event on your control. Just like buttons and other controls have events (like .Click), you would need to create one to expose the dropdownlist's change event.

In your UserControl class:

Public Event ValueChanged(ValueID as Integer)

In the DropDownList SelectedIndexChanged event handler:

RaiseEvent ValueChanged(CType(ddl.SelectedValue, Integer))

Then in the page that uses your user control you use the same syntax to handle this event:

Sub myControl_ValueChanged(nValueID As Integer) Handles myControl.ValueChanged
   'Handle event here
   'Because the event passed you the ValueID,
   'you don't need to get it from the control
   'Just use nValueID in the code
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
setting Collection properties for user control PurpleHaze VS.NET 2002/2003 2 December 30th, 2008 02:41 AM
Chane Properties of a user control from MasterPage slim182 ASP.NET 2.0 Basics 1 February 26th, 2007 09:54 PM
Referencing Fields within Tab Control Pages -Help TomW Access VBA 1 October 30th, 2006 01:31 PM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM





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