Mondeo Posted May 18, 2007 Posted May 18, 2007 Hi, I have a user control dropped onto a web form, the user control contains four textboxes. From the main form how can I access one of the text boxes on the user control (I just want to read its text property) Also, while on subject how to you do it the other way round? How does the user control access the form properties? Thanks Quote
Administrators PlausiblyDamp Posted May 18, 2007 Administrators Posted May 18, 2007 The easiest way of doing the 1st part is to expose the information from the user control as one or more properties, this way they can be accessed from the containing page. As to doing it the other way round that would be a bit more complicated - what kind of information would the control need to know about the page it is on? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mondeo Posted May 18, 2007 Author Posted May 18, 2007 Cheers, How do I expose the textbox1.text property? Or would I need to do something like the following Class UserControl Public Property TextBox1Value as string ..... End Property Private Sub TextBox1.TextChanged handles TextBox1.TextChanged me.TextBox1Value = TextBox1.Text End Sub End Class Regarding the 2nd point, I wanted to bind to a datagrid on the main page based on the values in the usercontrol. Thanks Quote
MrPaul Posted May 18, 2007 Posted May 18, 2007 Exposing individual TextBox properties or actual TextBox You can either expose individual TextBox properties as required: Public Property TextBoxText As String Get Return myTextBox.Text End Get Set myTextBox.Text = Value End Set End Property Or you could expose the TextBox itself, allowing external code to access all the properties, methods, and events of the TextBox: Public ReadOnly Property MyTextBox As TextBox Get Return myTextBox End Get End Property Which you use depends upon how much of the TextBox you wish to expose. Good luck :cool: Quote Never trouble another for what you can do for yourself.
Mondeo Posted May 21, 2007 Author Posted May 21, 2007 Thanks, works fine. Can I expose properties of the parent form in the same way? Quote
Mondeo Posted May 21, 2007 Author Posted May 21, 2007 Sorry i'm wrong it doesn't work, the property is not visible in intellisense. This is in my capsearch.asmx user control Public ReadOnly Property CapCode() As String Get If ddlDerivative.SelectedValue <> -1 Then Return ddlDerivative.SelectedValue Else Return "0" End If End Get End Property Then I have declared the usercontrol on the web form like so <div id="wrapper"> <div id="cl"> <CAP:CAPSearch ID="CAPSearch" runat="server"/><br clear="all"/> </div></div> In my code behind for the page I can access CapSearch, theres loads of standard properties like Application, Attributes, Cache etc - but no CapCode. What have I done wrong? Thanks Quote
MrPaul Posted May 22, 2007 Posted May 22, 2007 Intellisense in ASP.Net Does it work if you type CapCode anyway (without intellisense)? I've often experienced intellisense quirks in ASP.Net. Sometimes rebuilding the project helps, but not always. Quote Never trouble another for what you can do for yourself.
Mondeo Posted May 22, 2007 Author Posted May 22, 2007 Rebuild all fixed it, thanks. And i've figured out going by other way by using newcontrol = me.parent.findcontrol("control") Cheers Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.