UserControl Property Problem: Need help

I

Ing. Rajesh Kumar

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
 
S

Sergey Poberezovskiy

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:
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top