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
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