Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Webuser control exposes properties/methos etc.???


Message #1 by "Dale Purdon" <dale@t...> on Thu, 6 Mar 2003 16:04:28 +0200
Hi all,

 

I have created a web user control in ASP.NET. It basically contains a
few text boxes, a search button, and a datagrid. Now, I have put this
control onto my webform. But I want to be able to expose properties from
the web user control and access them from the container web form1.

 

Eg?

 

----code in my webform

 

Mywebusercontrol.textbox.text = ?whatever?

 

 

Is this possible?

 

thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003
 

Message #2 by "Peter Lanoie" <planoie@n...> on Thu, 6 Mar 2003 10:34:09 -0500
The problem is that your user control has a textbox and it's "Protected".
Your webform includes the control, but cannot see the textbox.

UserControl:

	Protected WithEvents txtMyTextBox As System.Web.UI.WebControls.TextBox


There are several ways of making it visible:

A) Make the textbox public

	Public WithEvents txtMyTextBox As System.Web.UI.WebControls.TextBox

Then you need to access it with "MyUserControl.txtMyTextBox".  That's kind
of dirty though.

B) Add a public var that references the protected textbox.

	Protected WithEvents txtMyTextBox As System.Web.UI.WebControls.TextBox
	Public MyTextBox As System.Web.UI.WebControls.TextBox = txtMyTextBox

C) Add a public Property to access the protected textbox.

	Protected WithEvents txtMyTextBox As System.Web.UI.WebControls.TextBox
	Public Property MyTextBox() As System.Web.UI.WebControls.TextBox
		Get
			MyTextBox = txtMyTextBox
		End Get
		Set(ByVal Value As System.Web.UI.WebControls.TextBox)
			txtMyTextBox = Value
		End Set
	End Property

I would recommend either B or C.  There has been a discussion on another
forum regarding the use of public vars vs properties.  In a case like this,
I think you are safe to use a public var for the text box as there is little
that you need control over that you can deal with in a property for a
control.

Peter


-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: Thursday, March 06, 2003 09:04
To: aspx_beginners
Subject: [aspx_beginners] Webuser control exposes properties/methos
etc.???


Hi all,



I have created a web user control in ASP.NET. It basically contains a
few text boxes, a search button, and a datagrid. Now, I have put this
control onto my webform. But I want to be able to expose properties from
the web user control and access them from the container web form1.



Eg



----code in my webform



Mywebusercontrol.textbox.text = whatever





Is this possible?



thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003




Message #3 by "Dale Purdon" <dale@t...> on Fri, 7 Mar 2003 09:59:57 +0200
Thanks Peter,

One more thing (may sound a bit stupid but), from the webform that my
control is placed on, how do I access it at all, I see that a web user
control is an abstract class (MustInherit). How do I actually access it?

Something like...

strWhatever =3D Me.MyWebcontrol.txtTextbox.Text

OR

strWhatever =3D MyWebcontrol.txtTextbox.Text


(do I have to actually have to create an instance of it?)

Thanks again.

-----Original Message-----
From: Peter Lanoie [mailto:planoie@n...]
Sent: 06 March 2003 05:34 PM
To: aspx_beginners
Cc: dale@t...
Subject: [aspx_beginners] RE: Webuser control exposes properties/methos
etc.???

The problem is that your user control has a textbox and it's
"Protected".
Your webform includes the control, but cannot see the textbox.

UserControl:

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox


There are several ways of making it visible:

A) Make the textbox public

	Public WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox

Then you need to access it with "MyUserControl.txtMyTextBox".  That's
kind
of dirty though.

B) Add a public var that references the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public MyTextBox As System.Web.UI.WebControls.TextBox =3D
txtMyTextBox

C) Add a public Property to access the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public Property MyTextBox() As System.Web.UI.WebControls.TextBox
		Get
			MyTextBox =3D txtMyTextBox
		End Get
		Set(ByVal Value As System.Web.UI.WebControls.TextBox)
			txtMyTextBox =3D Value
		End Set
	End Property

I would recommend either B or C.  There has been a discussion on another
forum regarding the use of public vars vs properties.  In a case like
this,
I think you are safe to use a public var for the text box as there is
little
that you need control over that you can deal with in a property for a
control.

Peter


-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: Thursday, March 06, 2003 09:04
To: aspx_beginners
Subject: [aspx_beginners] Webuser control exposes properties/methos
etc.???


Hi all,



I have created a web user control in ASP.NET. It basically contains a
few text boxes, a search button, and a datagrid. Now, I have put this
control onto my webform. But I want to be able to expose properties from
the web user control and access them from the container web form1.



Eg=05



----code in my webform



Mywebusercontrol.textbox.text =3D =13whatever=14





Is this possible?



thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003






---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


Message #4 by "Dale Purdon" <dale@t...> on Fri, 7 Mar 2003 10:16:59 +0200
Got it,

...from webform

Protected mywebcontrol as NameOfMyWebUserControlClass


...by the way, what is a good standard naming convention to use for
declaring web user controls?

-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: 07 March 2003 10:00 AM
To: 'aspx_beginners'
Subject: RE: [aspx_beginners] RE: Webuser control exposes
properties/methos etc.???

Thanks Peter,

One more thing (may sound a bit stupid but), from the webform that my
control is placed on, how do I access it at all, I see that a web user
control is an abstract class (MustInherit). How do I actually access it?

Something like...

strWhatever =3D Me.MyWebcontrol.txtTextbox.Text

OR

strWhatever =3D MyWebcontrol.txtTextbox.Text


(do I have to actually have to create an instance of it?)

Thanks again.

-----Original Message-----
From: Peter Lanoie [mailto:planoie@n...]
Sent: 06 March 2003 05:34 PM
To: aspx_beginners
Cc: dale@t...
Subject: [aspx_beginners] RE: Webuser control exposes properties/methos
etc.???

The problem is that your user control has a textbox and it's
"Protected".
Your webform includes the control, but cannot see the textbox.

UserControl:

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox


There are several ways of making it visible:

A) Make the textbox public

	Public WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox

Then you need to access it with "MyUserControl.txtMyTextBox".  That's
kind
of dirty though.

B) Add a public var that references the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public MyTextBox As System.Web.UI.WebControls.TextBox =3D
txtMyTextBox

C) Add a public Property to access the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public Property MyTextBox() As System.Web.UI.WebControls.TextBox
		Get
			MyTextBox =3D txtMyTextBox
		End Get
		Set(ByVal Value As System.Web.UI.WebControls.TextBox)
			txtMyTextBox =3D Value
		End Set
	End Property

I would recommend either B or C.  There has been a discussion on another
forum regarding the use of public vars vs properties.  In a case like
this,
I think you are safe to use a public var for the text box as there is
little
that you need control over that you can deal with in a property for a
control.

Peter


-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: Thursday, March 06, 2003 09:04
To: aspx_beginners
Subject: [aspx_beginners] Webuser control exposes properties/methos
etc.???


Hi all,



I have created a web user control in ASP.NET. It basically contains a
few text boxes, a search button, and a datagrid. Now, I have put this
control onto my webform. But I want to be able to expose properties from
the web user control and access them from the container web form1.



Eg=05



----code in my webform



Mywebusercontrol.textbox.text =3D =13whatever=14





Is this possible?



thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003






---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


Message #5 by "Peter Lanoie" <planoie@n...> on Tue, 18 Mar 2003 11:44:54 -0500
Dale,

We make our user controls like this:
File: ucSomeControl.ascx
Class name: ucSomeControl

You may want to put the controls in a specific sub directory to organize
them.

Peter

-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: Friday, March 07, 2003 03:17
To: aspx_beginners
Subject: [aspx_beginners] FW: RE: Webuser control exposes
properties/methos etc.???


Got it,

...from webform

Protected mywebcontrol as NameOfMyWebUserControlClass


...by the way, what is a good standard naming convention to use for
declaring web user controls?

-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: 07 March 2003 10:00 AM
To: 'aspx_beginners'
Subject: RE: [aspx_beginners] RE: Webuser control exposes
properties/methos etc.???

Thanks Peter,

One more thing (may sound a bit stupid but), from the webform that my
control is placed on, how do I access it at all, I see that a web user
control is an abstract class (MustInherit). How do I actually access it?

Something like...

strWhatever = Me.MyWebcontrol.txtTextbox.Text

OR

strWhatever = MyWebcontrol.txtTextbox.Text


(do I have to actually have to create an instance of it?)

Thanks again.

-----Original Message-----
From: Peter Lanoie [mailto:planoie@n...]
Sent: 06 March 2003 05:34 PM
To: aspx_beginners
Cc: dale@t...
Subject: [aspx_beginners] RE: Webuser control exposes properties/methos
etc.???

The problem is that your user control has a textbox and it's
"Protected".
Your webform includes the control, but cannot see the textbox.

UserControl:

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox


There are several ways of making it visible:

A) Make the textbox public

	Public WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox

Then you need to access it with "MyUserControl.txtMyTextBox".  That's
kind
of dirty though.

B) Add a public var that references the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public MyTextBox As System.Web.UI.WebControls.TextBox 
txtMyTextBox

C) Add a public Property to access the protected textbox.

	Protected WithEvents txtMyTextBox As
System.Web.UI.WebControls.TextBox
	Public Property MyTextBox() As System.Web.UI.WebControls.TextBox
		Get
			MyTextBox = txtMyTextBox
		End Get
		Set(ByVal Value As System.Web.UI.WebControls.TextBox)
			txtMyTextBox = Value
		End Set
	End Property

I would recommend either B or C.  There has been a discussion on another
forum regarding the use of public vars vs properties.  In a case like
this,
I think you are safe to use a public var for the text box as there is
little
that you need control over that you can deal with in a property for a
control.

Peter


-----Original Message-----
From: Dale Purdon [mailto:dale@t...]
Sent: Thursday, March 06, 2003 09:04
To: aspx_beginners
Subject: [aspx_beginners] Webuser control exposes properties/methos
etc.???


Hi all,



I have created a web user control in ASP.NET. It basically contains a
few text boxes, a search button, and a datagrid. Now, I have put this
control onto my webform. But I want to be able to expose properties from
the web user control and access them from the container web form1.



Eg



----code in my webform



Mywebusercontrol.textbox.text = whatever





Is this possible?



thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003






---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003





  Return to Index