Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: User Control Public Properties


Message #1 by "Alvin Ling" <alvin.ling@i...> on Wed, 13 Feb 2002 16:32:33 -0500
This might be a basic problem and I'm not even sure I'm on the right

track...



I have a user control to display an address form (street, city, state,

etc...).  Different form elements should be displayed based on whether

or not the address form is initialized as a US or International form

(via a public SetCountry method).  



I've accomplished the conditional display of the required elements by

including two sets of server controls (i.e. a dropdownlist of states for

US and a textbox for International) and setting the Visibility property.



I've hit a wall trying to set up public properties for the form.  I'd

like to be able to have the logic built into the Get/Set of the property

to determine which control value (i.e. ddlStateUS.SelectedItem.Value or

txtStateIntl.Text) to return.



Can someone help me fill in the ???? below?  If I'm completely off

track, can someone point me in the right direction?





----- The code-behind for my user control -----



Public Class CustomerAddress : Inherits UserControl



	Protected ddlStateUS As Dropdownlist

	Protected txtStateIntl As Textbox

	Protected txtZipUS As Textbox

	Protected txtZipIntl As Textbox



	Public Sub SetCountry(ByVal addressCountry As String)

	

		If addressCountry = "United States" Then

			ddlStateUS.Visible = true

			txtStateIntl.Visible = false

			txtZipUS.Visible = true

			txtZipIntl.Visible = false

		Else

			ddlStateUS.Visible = false

			txtStateIntl.Visible = true

			txtZipUS.Visible = false

			txtZipIntl.Visible = true

		End If



	End Sub



	Public Property State As String

		Get

			??????

		End Get

		Set

			??????

		End Set

	End Property



	Public Property Zip As String

		Get

			??????

		End Get

		Set

			??????

		End Set

	End Property



End Class









Message #2 by "Robert Colbert" <rcolbert@n...> on Thu, 28 Feb 2002 18:49:39
I didn't see a reply in the web archive, so I'll give it a shot. 



Inside the get/set, simply base your logic on the visibility of one of 

the items ... i.e. ddlStateUS.  You should only need to do this for the 

Set state as you should declaring the property there as a string.



<code snip>

 	Dim StateValue as String

 	Public Property State As String

 		Get

 			Return StateValue

 		End Get

 		Set

 			If (ddlStateUS.Visible) Then

 				StateValue = 

ddlStateUS.SelectedItem.Value 

 			Else

 				StateValue = txtStateIntl.Text

 			End If

 		End Set

 	End Property

</code snip>



Hope this makes sense and helps.

-Robert



> This might be a basic problem and I'm not even sure I'm on the right

> track...

> 

> I have a user control to display an address form (street, city, state,

> etc...).  Different form elements should be displayed based on whether

> or not the address form is initialized as a US or International form

> (via a public SetCountry method).  

> 

> I've accomplished the conditional display of the required elements by

> including two sets of server controls (i.e. a dropdownlist of states for

> US and a textbox for International) and setting the Visibility property.

> 

> I've hit a wall trying to set up public properties for the form.  I'd

> like to be able to have the logic built into the Get/Set of the property

> to determine which control value (i.e. ddlStateUS.SelectedItem.Value or

> txtStateIntl.Text) to return.

> 

> Can someone help me fill in the ???? below?  If I'm completely off

> track, can someone point me in the right direction?

> 

> 

> ----- The code-behind for my user control -----

> 

> Public Class CustomerAddress : Inherits UserControl

> 

> 	Protected ddlStateUS As Dropdownlist

> 	Protected txtStateIntl As Textbox

> 	Protected txtZipUS As Textbox

> 	Protected txtZipIntl As Textbox

> 

> 	Public Sub SetCountry(ByVal addressCountry As String)

> 	

> 		If addressCountry = "United States" Then

> 			ddlStateUS.Visible = true

> 			txtStateIntl.Visible = false

> 			txtZipUS.Visible = true

> 			txtZipIntl.Visible = false

> 		Else

> 			ddlStateUS.Visible = false

> 			txtStateIntl.Visible = true

> 			txtZipUS.Visible = false

> 			txtZipIntl.Visible = true

> 		End If

> 

> 	End Sub

> 

> 	Public Property State As String

> 		Get

> 			??????

> 		End Get

> 		Set

> 			??????

> 		End Set

> 	End Property

> 

> 	Public Property Zip As String

> 		Get

> 			??????

> 		End Get

> 		Set

> 			??????

> 		End Set

> 	End Property

> 

> End Class

> 

> 

> 

> 


  Return to Index