Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > User Control question - REPOSTED

Reply
Thread Tools

User Control question - REPOSTED

 
 
Brian Cesafsky
Guest
Posts: n/a
 
      05-02-2006
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").FindCont rol("txtInterestRate")
tempString = currentTextBox.Text



Thanks in advance! Brian


 
Reply With Quote
 
 
 
 
Kelly Leahy
Guest
Posts: n/a
 
      05-02-2006
Brian,

You should add a property to your code behind file and have the property act
as a proxy for the information you want to expose.

For instance,

Public Property Get TheFirstTextBox( ) As TextBox
Return Me.TextBox1
End Property

Then, you should be able to access the property through your code on the page.

Cheers,
Kelly

"Brian Cesafsky" wrote:

> 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").FindCont rol("txtInterestRate")
> tempString = currentTextBox.Text
>
>
>
> Thanks in advance! Brian
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JoSQL reposted Sharp Tool Java 4 10-23-2005 03:25 PM
moggie has to GO. (reposted due to lack of feedback and maybe cos noone follows rogers posts)) Brian Computer Support 32 10-02-2005 01:14 AM
fire wall problem reposted Mechdaddy Computer Support 0 06-26-2004 12:38 PM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM
% Ultra Newbie Question % (Reposted - Better version) Tayna Taylor Javascript 1 11-30-2003 03:31 AM



Advertisments