Home All Groups Group Topic Archive Search About
Author
25 Apr 2006 7:55 PM
Brian Cesafsky
I am using framework 1.1

I have a user control and a web page.

I want to set up properties on the user control, so I can access the text
boxes on the user control when I am in the code behind page of the 'main'
web page.

I have done this so far...


1)  On the user control... in the #Region " Web Form Designer Generated Code
" I have 2 text boxes (for simplicity of this question).  If I am on the
main web page and I want to access the text boxes on the user control, I
have to change the defenition of the text box from  Protected WithEvents to
Protected Shared WithEvents.  Then I create the property like this in the
user control...

Public Class AccountCenterGeneral
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub

Protected Shared WithEvents txtSalesTaxPercent As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtNotes As System.Web.UI.WebControls.TextBox
#End Region

Public Property Notes() As String
Get
Return txtNotes.Text
End Get

Set(ByVal Value As String)
txtNotes.Text = Value
End Set
End Property



2)  In the main web page, I can then code this to access the text box

    dim tempString as string
    tempString = AccountCenterGeneral.Notes     (AccountCenterGeneral is the
name of my class in the user control)



THE PROBLEM... often times, if I make a change to the user control, ALL of
my definitions for the controls get changed back to Protected WithEvents
automatically and I have to reset them to Protected Shared WithEvents.  So
I'm wondering if I am doing this all wrong, or if I should go back to using
this type of code... (can anyone explain which way is better)?



dim tempString as string
Dim currentTextBox As TextBox
currentTextBox =
Page.FindControl("AccountCenterGeneral1").FindControl("txtInterestRate")
tempString  = currentTextBox.Text



Thanks in advance!    Brian

Author
7 May 2006 4:27 AM
Nathan Sokalski
First, are you absolutely sure you need to have the keyword Shared in there?
None of the books I have read say you should. Also, in the code you show,
the control you are accessing in the Property Accessor functions (txtNotes)
you don't have the keyword Shared, anyway. I haven't seen everything you
have tried, or all of your code, so I won't declare you wrong yet, but I
have a feeling the cause of your problem is somewhere other than your
properties. Something that I might try to do is find a good example of a
UserControl that has properties and see how they do it (I'm sure that with a
little effort you can find one somewhere on the web). Good Luck!
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"Brian Cesafsky" <brian.cesaf***@autotrackerplus.com> wrote in message
news:eL8sFJKaGHA.4784@TK2MSFTNGP02.phx.gbl...
>I am using framework 1.1
>
> I have a user control and a web page.
>
> I want to set up properties on the user control, so I can access the text
> boxes on the user control when I am in the code behind page of the 'main'
> web page.
>
> I have done this so far...
>
>
> 1)  On the user control... in the #Region " Web Form Designer Generated
> Code
> " I have 2 text boxes (for simplicity of this question).  If I am on the
> main web page and I want to access the text boxes on the user control, I
> have to change the defenition of the text box from  Protected WithEvents
> to
> Protected Shared WithEvents.  Then I create the property like this in the
> user control...
>
> Public Class AccountCenterGeneral
> Inherits System.Web.UI.UserControl
>
> #Region " Web Form Designer Generated Code "
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
> End Sub
>
> Protected Shared WithEvents txtSalesTaxPercent As
> System.Web.UI.WebControls.TextBox
> Protected WithEvents txtNotes As System.Web.UI.WebControls.TextBox
> #End Region
>
> Public Property Notes() As String
> Get
> Return txtNotes.Text
> End Get
>
> Set(ByVal Value As String)
> txtNotes.Text = Value
> End Set
> End Property
>
>
>
> 2)  In the main web page, I can then code this to access the text box
>
>    dim tempString as string
>    tempString = AccountCenterGeneral.Notes     (AccountCenterGeneral is
> the
> name of my class in the user control)
>
>
>
> THE PROBLEM... often times, if I make a change to the user control, ALL of
> my definitions for the controls get changed back to Protected WithEvents
> automatically and I have to reset them to Protected Shared WithEvents.  So
> I'm wondering if I am doing this all wrong, or if I should go back to
> using
> this type of code... (can anyone explain which way is better)?
>
>
>
> dim tempString as string
> Dim currentTextBox As TextBox
> currentTextBox =
> Page.FindControl("AccountCenterGeneral1").FindControl("txtInterestRate")
> tempString  = currentTextBox.Text
>
>
>
> Thanks in advance!    Brian
>
>