UserControl Property Problem: Need help

Discussion in 'ASP .Net' started by Ing. Rajesh Kumar, Apr 30, 2004.

  1. I have a UserControl with a TextBox "TextBox_1" and a ReadOnly Property "myText" in it. I am using this in a file (no Code Behind) as follows :
    HTML:
    <My:Control ID="txtName" runat="server" />
    VB:
    Dim var_1 as String = txtName.myText
    Till here everything works fine.

    Now I am trying to convert my file to a Code Behind file and here starts my problem.
    <My:Control ID="txtName" runat="server" /> is in WebForm1.aspx now and
    Dim var_1 as String = txtName.myText is in WebForm1.aspx.vb.
    During the compilation it says "txtName is not declared", which I understand because I cannot declare it using the similar command as follows:
    Protected txtNotes As System.Web.UI.WebControls.TextBox

    So my question is how should I declare "txtName" to use it in a CodeBehind ?
    I read a lot in MSDN but could not find the answer.

    Thanks in advance
    Raja
     
    Ing. Rajesh Kumar, Apr 30, 2004
    #1
    1. Advertising

  2. Raja,

    If you put the following line of code into your
    WebForm1.aspx.vb file:

    Protected WithEvents txtName as UserControl1

    (put the actual class name instead of UserControl1) - then
    you should be able to compile and use your control in code.

    Hope this helps.

    Sergey

    >-----Original Message-----
    >I have a UserControl with a TextBox "TextBox_1" and a

    ReadOnly Property "myText" in it. I am using this in a
    file (no Code Behind) as follows :
    >HTML:
    ><My:Control ID="txtName" runat="server" />
    >VB:
    >Dim var_1 as String = txtName.myText
    >Till here everything works fine.
    >
    >Now I am trying to convert my file to a Code Behind file

    and here starts my problem.
    ><My:Control ID="txtName" runat="server" /> is in

    WebForm1.aspx now and
    >Dim var_1 as String = txtName.myText is in

    WebForm1.aspx.vb.
    >During the compilation it says "txtName is not declared",

    which I understand because I cannot declare it using the
    similar command as follows:
    > Protected txtNotes As

    System.Web.UI.WebControls.TextBox
    >
    >So my question is how should I declare "txtName" to use

    it in a CodeBehind ?
    >I read a lot in MSDN but could not find the answer.
    >
    >Thanks in advance
    >Raja
    >
     
    Sergey Poberezovskiy, Apr 30, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    692
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    418
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,546
  4. Fabiano
    Replies:
    2
    Views:
    604
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
  5. Mark van Bree

    Postback problem with usercontrol in usercontrol

    Mark van Bree, May 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    165
Loading...

Share This Page