'ASP.Test_ascx.UserName' is not accessible in this context because it is 'Protected'.

M

Murphy

I am trying to learn how to access a web control in an ascx from the aspx
page. I have read over and over different articles realting to creating a
class, using the protected keyword etc but still without success.

From what i understand I need to expose the ascx control as a property of
the user control so that it can be accessed from the aspx page, I think this
is done using the following code for my ascx file:

<%@ Control Language="VB" %>
<script runat="server">
public class DisplayTesting
Inherits System.Web.UI.UserControl

Private _UserName As TextBox
Public Property Username() As Textbox
GET
Return _UserName
End Get

SET
_UserName=value
End Set
End Property

End Class
</script>
<asp:TextBox id="UserName" runat="server"></asp:TextBox>


The code for the aspx page is as follows however I am unsure of how to
access the text box in the ascx file:

<%@ Page Language="VB" %>
<%@ Register TagPrefix="Murphy" TagName="Body" Src="Test.ascx" %>
<script runat="server">

Sub Submit_Click(sender As Object, e As EventArgs)
Body.UserName="henry"
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<Murphy:Body id="Body" runat="server"></Murphy:Body>
<br />
<asp:Button id="Submit" onclick="Submit_Click" runat="server"
Text="Submit"></asp:Button>
</form>
</body>
</html>

The code above is a simplified example to help me learn the concepts, the
production project involves an aspx file with a webform containinig 15
controls all of which need to be accessed by the aspx page.


Any help would be greatly appreciated.

Thanks

Murphy
 
F

Fred Hirschfeld

Do you not have a code behind for this ascx control? What development
environment are you using?
 
M

Murphy

Have now solved thanks Fred, was using web matrix with the code between the
script tags...
 

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

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,202
Latest member
MikoOslo

Latest Threads

Top